Salem 5,265 Posting Sage

When testing what assembler will be produced, don't use main() as the example function. Being the special function where the program starts, it tends to accumulate baggage which isn't present in any other function.

Eg.

void foo ( ) {
	int a, d;

	int b=12;
	int c=13;

	a=b+c;
	d=b+c;
}

int main(void) {
    foo();
    return 0;
}


$ gcc -S foo.c && cat foo.s
_foo:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $16, %esp
        movl    $12, -12(%ebp)
        movl    $13, -16(%ebp)
        movl    -16(%ebp), %eax
        addl    -12(%ebp), %eax
        movl    %eax, -4(%ebp)
        movl    -16(%ebp), %eax
        addl    -12(%ebp), %eax
        movl    %eax, -8(%ebp)
        leave
        ret
# In other words, it does exactly what the code says

$ gcc -S -O2 foo.c && cat foo.s
_foo:
        pushl   %ebp
        movl    %esp, %ebp
        popl    %ebp
        ret
# The optimiser realises the results are never used, and the code is gone.

If foo() is declared 'static', then there isn't even that much. There is no function at all, and main() doesn't call it.

> has the opinion that you can always write better code with assembly as long
> as you stick with functions and the complexity stays low
It's certainly always "possible", and nobody is going to disagree that given enough time and experience, you can produce the equivalent translation which is better than the compiler.
But when you can write code in a high level language which achieves 95% of the performance with only 5% of the coding effort, you really need …

n.aggel commented: very helpful! +1
Salem 5,265 Posting Sage

> if each of us had planted our own vegetation and food in general and then trade
1. Unless you're already a farmer, or rich enough to own a house with a substantial garden, then very few people have the resources to plant enough crop to sustain themselves.
2. If you dedicated enough time to tending your own crop, what else would you fill your day with? Could you afford the time to go to school for instance?

The human race took a big step forward when trade permitted the specialisation of skills, which started when farmers were able to produce more food than they needed for themselves. Freed from the need to produce all your own food for example, you could trade your skill (say making axes) for some food. Axes evolved from the rock flake tied to a stick because the axe maker could dedicate time to improving the product with specialist knowledge.

From a subsistence base, who for example would have enough time to learn enough biology to create a vaccine for the latest disease which is wiping out the population?
There aren't that many "tree-huggers" who are hard-core enough to forego every single trapping of the modern world.

If the whole planet went back to subsistence farming, then you're looking at massive land and people redistribution, and a significant reduction in world population.

> personally, i wouldn't mind the use of a bicycle or an animal for travel

joshSCH commented: Wow.. couldn't have said it better myself :) +12
Salem 5,265 Posting Sage

Don't tell me we have to wait until 2012 before people stop posting to this thread ;)

Dave Sinkula commented: Heh. +11
Salem 5,265 Posting Sage

Well despite their C++ skills, there's already one glaring security hole just waiting to be exploited.

Writing internet facing applications needs a lot more security awareness than this. Using languages which protect you from dumb stuff like unguarded reads into finite length char arrays for example.

iamthwee commented: excellent point! +12
Salem 5,265 Posting Sage

strtod() would be a better function to use, because it has better error diagnostics.

iamthwee commented: Very true +15
Salem 5,265 Posting Sage

> for (a>6;a<=i;a++); //Execution of the series
> if (a%2!=0); // calculating the odd numbers
The trailing ; on both these lines is a huge problem.

Next time, use [code]
[/code] tags around your code.

iamthwee commented: There is a [noparse] code tag :) +11
Salem 5,265 Posting Sage

http://c-faq.com/lib/notveryrand.html
You might want to check on the quality of your rand() function.

Dave Sinkula commented: Thanks for following up on my laziness. +11
Salem 5,265 Posting Sage

Well while you're thinking about it, consider improving your English.
http://catb.org/~esr/faqs/smart-questions.html#writewell

Some boards might tolerate the kiddie speak, but this board doesn't, and there's no way you'd get a job if your CV looked like that.

Also, there seems to be a rash of people unable to think for themselves.

Ezzaral commented: Agreed. It's rather sad. +3
Salem 5,265 Posting Sage
iamthwee commented: excellent link +11
Salem 5,265 Posting Sage

The airline problem ceased to be interesting when smoking was banned. One of the key tasks was separating the smoking and non-smoking seats.

Also, problems have a memetic quality, in that each succession of noobs find out from their immediate predecessors where all the best places to ask questions are to be found.

Dave Sinkula commented: Bring back the smoking-related problems... please? +11
iamthwee commented: Using memetic and noob both in the same sentence deserves green candy! Charles Darwin, would be dancing in his grave. +11
Salem 5,265 Posting Sage
Aia commented: Nothing help so much as a good example. +3
Salem 5,265 Posting Sage

The usual problem is trying to mix say
cin >> somevar;
with getline().

They don't play well together, since a simple cin will leave a newline on the input stream, and this is exactly what getline stops at (thus giving the illusion of it being skipped).

Exactly how to get round this has been discussed endlessly on the forum and in the snippets section, perhaps look there.

Personally, I go with reading ALL input with getline, then convert from a string in memory. Trying to mix input and conversion all in one step almost always results in a mess in all but the most trivial of programs.

iamthwee commented: Good advice +11
Salem 5,265 Posting Sage

> int HotDogStand:: totalSales = 0 ;
This should be in ONE .cpp file only.

Duki commented: thanks! +4
Salem 5,265 Posting Sage

Yeah, the problem is you've been learning from people who never bothered to look at the standards. void main has never been a valid return type for main. Unfortunately for you, you've now got the pain of trying to unlearn something.

All compilers extend the language in some way, I guess you learnt with a compiler that blindly accepted void main without complaint. g++ is no different in that respect. g++ -W -Wall -ansi -pedantic prog.cpp does a pretty good job of reigning it back to being just an ANSI C++ compiler, where the code has a pretty good chance of being compiled with any other ANSI C++ compiler.


As for the return result, you do can something like this in say a bash script

./myprog
if [ $? == 0 ]; then
 echo success
fi

The shell variable $? contains the return value of the main in the program you most recently ran.

You can also get the return status in your C code if you want as well

pid = fork();
if ( pid == 0 ) {
  /* run your other program */
  execl("./prog", "./prog", (char*)NULL );
} else if ( pid != -1 ) {
  int status;
  wait( &status );
  /* when prog exits, the return result is in status (along with some other stuff) */
}

Use the various 'W' macros to find out whether it was a normal exit (and thus a valid return status), …

Narue commented: Cookie for Salem. +16
Salem 5,265 Posting Sage

> this is my third program,and errors are similar but i coulnot fix them
Like I said, the error is in your approach, namely trying to write too much code without pressing "compile" or running the results to make sure you're still on track.

Sooner or later, you'll have to learn how to do this, because nobody sits down and writes say "firefox" just by bashing the keyboard for several days, pressing compile and hey presto, instant working browser.

Think small, take baby steps, start with

int main ( ) {
  return 0;
}

Which becomes

void DisplayIntro();

int main ( ) {
  DisplayIntro();
  return 0;
}

void displayIntro()
{
    cout<<"EASTER DAY CALCULATION\n"
          "\n Enter two starting and ending years "
          "And the Easter days will be Displayed"
          "The Starting year must not be after the ending year and both years 
          "\nmust be integers in the range 1900-2099.\n";
}

Now, if you try to compile this second one, you'll see at least one problem. Try to fix it before moving on with the next step.

The next step is to add ONE MORE FUNCTION AT A TIME until you've built up the complete program. After making each function compile, run the code to make sure it does what you want.

Yes, anyone here could copy/paste the fixed solution, but that just isn't going to teach you anything at all about how to fix your own code, and you'll be back in a few …

WolfPack commented: Great advice for a beginner +7
GreenDay2001 commented: Really a thing that must be practiced and never ignored by novices. +3
Salem 5,265 Posting Sage

> Why use a do loop ?
It's one of the standard techniques to ensure that a multi-line macro such as this always appears as a single statement.
See http://www.c-faq.com/cpp/multistmt.html

@OP

>#define allocate_cube(type, var, x, y, z)                            \
>    do {                                                             \
>        (var) = malloc(sizeof(type **) * (x));                       \

You don't need to specify the type as a parameter to the macro. All the size information is available via the var, eg.

#define allocate_cube(var, x, y, z)                                  \
    do {                                                             \
        (var) = malloc(sizeof(*var) * (x));                          \

The general form being p = malloc ( n * sizeof *p ); This fixes the problem of doing something dumb, but hard to trace if it happens to work first time around, like this.

int ***array;
array = allocate_cube(double, array, 5, 10, 15);

> Another issue (as I see it) with macro vs functions in this case is that my macro is type-neutral
Or type-unsafe, depending on your point of view.
In reality, how many types are you going to be dealing with, and how often do you need a new type?

AD's suggestion of a function could be implemented simply as

int ***allocate_int_cube ( int x, int y, int z ) {
    int ***result = alloc_cube( result, x, y, z );
    return result;
}

The macro still does all the donkey work, but it's use is tightly controlled to just a small part of the overall program. The …

Salem 5,265 Posting Sage

Places to practice and hone your skills.
1. Any question asking for help on a forum such as this, just to see if you can do it. If you can do it, fine, but don't post the complete solution. Instead, offer hints to the solution which the OP can pick up on.
You only truly understand something when you can explain it in simple terms to someone else.

2. Online programming contests (scroll to end)
There are many sites which have a vast array of problems from the very simple to the very difficult.

3. Open Source
Find a small open source project which you can get excited about.
- Download the source, build it, run it
- Study the code in detail
- Read any other background information, such as developer guides, design documents, test documents, coding standards etc
- Lurk on the developer mailing lists for a while
- Study the code in detail
- Read through all the bugs, and pick one which has a very definite cause and effect which you can replicate locally.
- Try to find where it actually occurs in the code, and how to fix it
- Study the project submissions guidelines on how to submit the fix.
- If your change is accepted, feel fantastic! Then try a meatier problem :)

ndeniche commented: excelent suggestion +3
Salem 5,265 Posting Sage

gcc -I/abc/bcc/include prog.c A long session with the manual pages would be a good idea as well.

Salem 5,265 Posting Sage

> something is wrong, because for x i get 0 output,
If you had bothered to read the manual, you would have discovered that the trig functions work in radians, not degrees.

Duki commented: w00p, thanks! +4
Salem 5,265 Posting Sage

Don't they teach simple geometry in schools any more?
http://mathworld.wolfram.com/RotationMatrix.html

Hamrick commented: i hope you feel all smart and powerful now that you've put someone down... +0
WolfPack commented: Nothing wrong with giving a helpful link. +7
Salem 5,265 Posting Sage

You haven't figured out the do your own homework bit have you?
http://www.daniweb.com/forums/announcement118-2.html
At least make some attempt, just don't dump your assignment on the board 5 minutes after your tutor gave it to you.

Your choice of topic titles needs work as well.
http://catb.org/~esr/faqs/smart-questions.html#bespecific

Bench commented: well said +4
Salem 5,265 Posting Sage

Make a copy of 0 using dup() before you close it, so that you can dup() it again to get back to it.

IIRC

keep = dup(0);
close(0);
dup(fd);  // fd is now stdin
close(0);
dup(keep); // back to original stdin
SpS commented: Right +4
Salem 5,265 Posting Sage

The rename() function perhaps?

Salem 5,265 Posting Sage

> printf(buffer);
Never use a string you're not in complete control of as the format string for printf.
If anyone ever got a % character into that, your code would be seriously broken.
http://en.wikipedia.org/wiki/Format_string_attack

It's best to always use string constants for printf/scanf formats.

iamthwee commented: nice read +11
Salem 5,265 Posting Sage

http://www.lvr.com/usb.htm
As soon as you start messing with devices, your code becomes very unportable.

With good design, you can minimise the amount of code you need to port from one machine to another.

Salem 5,265 Posting Sage

You're using new style C++, so you need using namespace std; immediately after the #include line.

Another way would have been to write std::cout<< "In Add(), received " << x<< "an d" <<y<< "\n"; but that can get rather verbose.

> reuturn 0;
Is this copy/pasted from your IDE, or did you just type this in from memory? The latter is just a low value post as it is no longer possible to be sure of anything you're saying.

In future, mention actual error messages (copy/paste from the IDE), as this will almost certainly help in more complex situations.

SpS commented: Good ~SpS +3
Salem 5,265 Posting Sage

> buf=(char *)GlobalAlloc(GPTR,len+5);
> GetDlgItemText(hwndsl, IDC_SAVELOAD, buf, len + 5);
> ...
> if(buf==NULL)
It surely looks like you're using it before checking it to me.

> 1. Why is it a problem in my case?(I don't think it can cause the problem I described).
Let's see - your code doesn't work, and you assume success.
Tell me where the logical fallacy in your argument is.
Take every opportunity to check status results, so you get immediate and to the point diagnosis of a problem. As opposed to the code stumbling on for a while with garbage data and eventually failing for some non-related or less than obvious problem.

Does (for example) GetDlgItemText() always append a \0 ?
If not, then you're trying to open a filename with random garbage at the end.


> 3. Actualy the only way to use goto is with a condition
What's wrong with

if(buf==NULL)
{
    MessageBox(hwndsl,"Please enter the file name!","Request:",MB_OK);
}
else
{
    SAVE(buf);
}

Perhaps before you open the file, you could try loadfile.clear();

Bench commented: It looks that way to me too, unless his code formatting is that bad +3
Salem 5,265 Posting Sage

> //Creating programe to store names & display names with max of 30 characters char name[6][20]; There's the first problem.

> #include <iostream.h>
This is old-style C++.
New C++ should use

#include <iostream>
using namespace std;

If your compiler doesn't like that, then you definitely need a newer compiler.

> main()
Whilst this used to work, because it was assumed that main would return an int, you need to understand that such implicit behaviour is obsolete and you need to say what you mean, namely int main ( ) As for the length, then look at #include <cstring> // or string.h if you insist on older compilers Then later on len = strlen( name[i] );

krnekhelesh commented: Neat explanation +1
Salem 5,265 Posting Sage

> ...I get a buch on error messages...any reason why?
Maybe post a few examples?

> 1. Does my use of "while(num!=0)" make a differnce in the programs ability to read in the 1000 numbers
It assumes there is a number 0 in the file. If there isn't, then bad things can happen. while ( inFile >> num ) will at least exit the loop if there is any sign of trouble, or the end of the file.

> 2. What's wrong with using a break in a 'for' loop and what difference will/does it make?
Depends how "pure" you want your code to be. Some people regard "break" as just another goto, and would write for(int i=0;i<=counter && !found;i++)

Salem 5,265 Posting Sage

The avalanche has already begun, it is too late for the pebbles to vote - kosh

Truth is a 3-edged sword - kosh

Some people are like blisters, they show up when the work is done.

When all is said and done, more has been said than has been done.

Science gives you the means to fight a war, religion gives you a reason.

If you laid all the economists in the world in a long line head to feet, you still wouldn't reach a conclusion.

There are two secrets to success in life:
1. Don't tell them everything you know.
2.

The earth is borrowed from our children, not inherited from our parents - Indian proverb?

~s.o.s~ commented: More power pills than pacman. Rep++. :) +24
Salem 5,265 Posting Sage

http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
The math.h implementation of sqrt() could well use one (or more) of the methods outlined in the link.

You too could implement the algorithms, and not rely on "math.h".

Salem 5,265 Posting Sage
#include <string>
#include <sstream>
#include <iostream>
using namespace std;

int main ( ) {
    string input;

    if ( getline(cin,input) ) {
        istringstream convert(input);
        int result;
        if ( convert >> result ) {
            cout << "Success = " << result << endl;
        } else {
            cout << "Not an integer" << endl;
        }
    } else {
        cout << "No input" << endl;
    }

    return 0;
}

It might look like a lot of code compared to your 1-liner, but if you were to make your input bomb-proof, you'd be looking at a similar amount of code.

If your program does a lot of interactive I/O, then you'd create a number of wrapper functions to take care of some of the repetitiveness.

iamthwee commented: Dead right! +11
Killer_Typo commented: great little snippit you got there. +6
Salem 5,265 Posting Sage

> It's assigned a memory location of 0x6e615c31
Which looks a lot like a string fragment of "na\1"

The \ is telling, does it look like part of a filename perhaps?

I'm betting that you're copying a string into some other allocated memory, and this is where you observe the trashing of memory as a crash.

Aia commented: Let's make these thanks from new people count. ;-) +6
Salem 5,265 Posting Sage

> Read in 1000 numbers, each of which is between 10 and 100, inclusive.
Actually Narue, I think he was trying to declare an array with a subscript range.
It's still wrong, since all subscripts start at 0

So if you were going for an easy life, with the first 10 entries of the array wasted, it would be int range[101]; // 100 is last valid subscript For minimum space, it would be int range[100-10+1]; but you would need to remember to subtract 10 from whatever value you use to subscript.

More generally

#define MIN 10
#define MAX 100
int range[MAX-MIN+1];
...
range[value-MIN] = 0;

> 3. With regards the seenBefore.....i aint really sure how to get it to work
- Grab a pack of playing cards.
- Shuffle them.
- For this test, you're ignoring the suit and just looking at the rank. So C3 and D3 are the same when it comes to determining if you've seen it before.
- Deal the cards one at a time (aka reading from the file), and then think about the steps you need to perform to work out whether you've seen the card before (based on rank only).

You should end up with 2 piles of cards, the 'seen' pile containing 13 cards, and the 'duplicates' containing the other 39 cards.

Salem 5,265 Posting Sage

Shocking - only 15 out of 20, surely some mistake....

1. Which of the following is an example of compounded assignment statement?
a = 5
a += 5
a = b = c
a = b
Ans : 2

Since K&R doesn't actually define the term "compounded assignment", one is left guessing as to what the hell they're talking about. Their answer is correctly called an assignment operator.

4. The operator / can be applied to
integer values
float values
double values
All of these
Ans : 2

Apparently, we're supposed to use something other than / for division of ints and doubles :icon_rolleyes:

9. Which of the following operator has the highest precedence?
*
==
=>
+
Ans : 4

Since => isn't actually an operator, I toyed with the idea that it was a typo and it really meant ->
Their "answer" comes in from left field and complete levels anyone with any competence in C.

16. What will be the output of the expression 11 ^ 5?
5
6
11
None of these
Ans : 2

Yet more trouble for anyone who actually knows the answer rather than some chimp guessing away.

Somewhat strangely, it is the "right" answer if you assume that the "11" is in binary, and the "5" is decimal, but that sure is a contrived way of screwing …

Killer_Typo commented: i will make sure to avoid it as well! +6
Salem 5,265 Posting Sage

Oh good, what do I need to do to piss off the "Rash Fool" in order to further discredit this lousy rep system?

Bring it on fool, rep-wars++

I pity da fool who abuses rep - "Mr T"

Computer, turn this bloody thing off - "Scotty"

arjunsasidharan commented: lol :D +3
Salem 5,265 Posting Sage

> .i think the answer given to you is wrong.
Yes, just as wrong as yours is.
"it was a work of art - flawless, sublime. A triumph equalled only by its monumental failure" - The Architect.

Until you truly understand undefined behaviour (UB), you'll always struggle to come up with increasingly bizarre explanations of what is happening.

Only when you understand what UB really means will you realise that attempts at explaining it are pointless. All such explanations are simultaneously
- right ("works for me, today, with this compiler and this bit of code")
- wrong ("doesn't work for someone else")
- useless ("doesn't help anyone in the long run anyway")

Do the world a favour and read the C.L.C FAQ link I posted a couple of replies ago from end to end, and make sure you really know what UB and "sequence points" are.

Here's something to wrap your noodle around.

#include <stdio.h>

#define MUL(x,y) ((x)*(y))

int mul ( int x, int y ) {
    return x * y;
}

int main ( void ) {
    int a = 22;
    int b = 22;
    int r1 = MUL(a++,a++);
    int r2 = mul(b++,b++);
    printf("%d %d\n", r1, r2 );
    return 0;
}

$ gcc -W -Wall -ansi -pedantic foo.c && ./a.exe
484 506

It's the same code apparently, so why the different answers when compiled with gcc?

Aia commented: Thanks for the example. +6
Salem 5,265 Posting Sage

If you're trying to do

system( "cd \\the\\yellow\\brick\\road" );
ifstream fin( "lion.txt" );

then you're going about it all wrong. Any changes you make inside system() are localised to the sub-process which is created (and then lost almost immediately). The current directory seen by ifstream isn't at the end of the yellow brick road.

If you really want to open a file in another directory, then you need something like

chdir( "\\the\\yellow\\brick\\road" );
ifstream fin( "lion.txt" );

or

ifstream fin( "\\the\\yellow\\brick\\road\\lion.txt" );

But note that chdir() is a concept here, you need to find the actual name of the function which matches your OS/Compiler.

iamthwee commented: Too right, and much better than system calls which should be avoided at all costs. +11
Salem 5,265 Posting Sage

Why do you care?
Today's desktop PCs use virtual memory for allocating stack space, and the default initial size is usually around the 1MB mark. In windows for example, the stack is allocated on demand in 4K blocks at a time. Saving a few bytes here and there isn't going to matter.

Places where you might care.
- DOS (real DOS, not win32 console which many mistake for DOS), which has an upper limit of 64K for stack size.
- embedded systems or smaller micro processors which can have very small stacks, say a couple of hundred bytes.

> From wat I`ve heard, one of the best ways is to try and avoid static arrays in functions.
Which is exactly the wrong thing, because making arrays static takes them off the stack.

> Is there anything else?
In addition to the making large arrays static, you can add
- avoid recursion
- pass structs by reference (a const pointer), not by value
- group same sized variables together (for structs and for locals)
Eg.

int a;
short b;
int c;
char d;

may take up more space than this, due to all the internal padding and alignment.

int a;
int c;
short b;
char d;

- if you're passing the same group of variables (say x,y,z coordinates), then consider making a struct out of them, and see above.
- declare variables in the narrowest scope …

WolfPack commented: Damn good answer. +10
Salem 5,265 Posting Sage

My "instinct" is that most drugs should be legal.
In tandem with that, there should be some meaningful (and enforced) laws regarding their abuse. In particular, the penalty for killing someone whilst DUI is considerably less than for killing someone by any other method.

On the one hand, society should do something to protect the weak and vunerable, and help them recover from their mistakes. On the other hand, a minority of people will always find a way to harm themselves, and we should reserve a special place for them at http://www.darwinawards.com/

The vast majority of people it seems either have the sense to say "no", even when the drug is legal, or partake in it's use with no serious consequence to themselves or society at large.
The problem of course is that the minority have a disproportionate negative effect.

The US tried prohibition once. It didn't work then, and there's no reason to think that a "war on drugs" is going to work now. At best, it's an expensive stalemate maintaining the status quo. But it seems more likely to turn into another 1 or 2 decade miserable failure.

ISTR that the bulk production cost of cocaine is about the same as sugar, but the street price is inflated beyond all rationale in relation to the cost of production. None of that excessive price finds it's way back as a benefit to society at large.

Benefits of legalisation
- …

Rashakil Fol commented: You shouldn't be posting in the Geek's Lounge. Get out while you can. -2
Aia commented: Your instict may not be yet far from good reasoning +6
John A commented: Interesting. +14
Salem 5,265 Posting Sage

Some people might like the equality, but not the sum...

#include <stdio.h>

int sum ( const char *p ) {
    int result = 0;
    while ( *p ) {
        result += ( *p++ - 'A' + 1 ) * 9;
    }
    return result;
}

int main ( void ) {
    int answer;
    if ( (answer=sum("JESUS")) == sum("MESSIAH") ) {
        printf("%d\n",answer);
    }
    return 0;
}
~s.o.s~ commented: More power pills than pacman. :-) +23
Salem 5,265 Posting Sage

Use fgets() to read a line of input into a buffer, and check the result.

Use strchr() to step from one delimiter to the next for example.

Use strncpy() to copy string fragments, and make sure that a \0 is appended. Write your own version of strncpy() which automatically appends a \0.

Use strcpy() if you know the target string is at least as big as the input buffer. sscanf() string formats "%s" and "%[" are safe if the target strings are at least as large as the string being scanned.

Use strtol(), strtoul() and strtod() to convert integers, unsigned integers and floating point numbers from the buffer fgets() returned. Note that these functions also detect over/underflow, which sscanf() cannot do.

iamthwee commented: excellent summary +11
Aia commented: Nice +5
Salem 5,265 Posting Sage

> GetDiskFreeSpaceEx()
Dunno, but the 'df' command line program provides this information. If you could locate the Linux source for that program, perhaps you'll find out how it's done.

> GetFileAttribute()
Use the stat() API as described already. Should be good for regular files and directories.
Remember, if it returns -1, then look at the 'errno' variable to find out why it failed.

> GetModuleFileName()
The nearest equivalent is argv[0], as passed to your main()

> GetFileVersionInfoSize()
> GetFileVersion( )
AFAIK, there is no consistent way of putting version information into a file. Shared libraries in particular encode the version into the filename, but that's about it.

Salem 5,265 Posting Sage

> though not every compiler accepts the same syntax at all.
Yes they will.
If you take the trouble to learn the language as defined by ANSI/ISO, then you'll have no problem writing code which will work on any ANSI/ISO compatible compiler.

The reason most people come unstuck is the first time they try to use another compiler (or port their code). At that point, they realise they've been using 'dialect C'. In other words, the 'C' which their compiler will let them get away with, not the proper 'C'.

Continually compiling the same code with multiple compilers set at their max warning levels is a good way of making sure that your code is up to spec. Running lint is a good idea as well if you want that professional touch.

Salem 5,265 Posting Sage

> char ch = getchar();
It should be
int ch = getchar();

char holds all possible chars. To hold all possible chars and EOF, you need a bigger data type, thus int.

Nor is the returned value guaranteed to be -1, which is why there is a constant EOF declared for this purpose.

Eg.

int ch;
while ( (ch=getchar()) != EOF ) {
  /* do stuff */
}
Aia commented: right! +2
Salem 5,265 Posting Sage

> I can see there are many errors showing in the compiler,
> but whenever I try to fix the remaining errors, more appear!
Always start with the first one in the list. Everything else in the list can be a consequence of the compiler trying to make a guess as to how to fix the problem. Though with practice, you'll be able to filter out those and fix later actual errors as well in the same edit/compile cycle.

Also, it is entirely possible to write your code one line at a time, then press compile to see that it is OK. Then you never get into the situation of having lots of errors and no clue.
http://cboard.cprogramming.com/showthread.php?t=88495
In essence, never write more lines than you're prepared to deal with being wrong.

Aia commented: What more can be said?. Very good. +2
Salem 5,265 Posting Sage

The first problem with the rep system is that it is all-or-nothing "agree or disagree". So for people with lots of rep, they can only "strongly agree" or "strongly disagree".

For anyone familiar with devshed's approach (which I find much better in this respect), you can choose how many points to give up to your maximum (both maximum points per comment, and maximum reps per day). This for example allows you to politely (or jokingly) disagree with someone, without knocking them into the ground.

The second problem is one of "worth". As WolfPack says, who the rep came from and for what is far more important. Some oik with an axe to grind on the coffee house fora isn't worth a hill of beans to most people.

My suggestion would be that each forum should have a "scale factor" which is multiplied by the points you want to give to that person. In the coffee house, this scale factor is zero, so everyone can agree and disagree all they want, and nothing really changes. On all the other forums, the scale factor is 1 so that good posts are duly recognised and rewarded.

WolfPack commented: Interesting suggestion. +8
iamthwee commented: you need to get out more. -2
Sulley's Boo commented: void main'ers are DOOMed, i agree i agreeeeeee :eek: +3
Salem 5,265 Posting Sage

http://it.acronymfinder.com/af-query.asp?string=exact&acronym=csp&s=r
Maybe we can't figure out which meaning of CSP you're talking about.

> Is simple hill-climbing a complete algorithm for solving CSPs?
That looks like a google question to me, if you'd done any research on the topic.

Sturm commented: lol funny. +1
Salem 5,265 Posting Sage

Just do "Mark forum as read" at the end of every visit.

If it doesn't get a new "envelope" (on your next visit) indicating that there are new messages, it doesn't get read again.

If it's fallen off the first page, it doesn't get read either.

Plus, when you read the thread, there's a handy "goto first unread" link so you can immediately start with the new information.

That essentially makes "solved" a non-issue for me, because I don't care whether the OP can be bothered to accurately update the solved status of the thread (most of them can't anyway).

Salem 5,265 Posting Sage

Most of them can't even use code tags properly, despite water marks in edit windows, and sticky threads with titles like "new posters, read this first".

Still others seem to click on "solved" even when it isn't (I've just seen this scenario on the asm board).

Nor does marking it solved stop long dead threads from being resurrected by some "chippy" with some vague "me too" pith, again despite the warning that the thread has already been marked as "solved".

Most everyone else just abandons their thread just as soon as they have the answer (even when the answer was found on another board, or through their own efforts).

For me, threads a "self solved" by not being on the first two pages. If the OP doesn't keep it alive by adding new information, then it becomes solved by default in my book.

It just looks like lots of extra work for the mods, reading each post to see if the question has reached a conclusion.

John A commented: Well said. +13