Sunday, August 2, 2009

Program does not work the way specified in C (read the Comment)?

/* Goo Go Gaa Ga.cpp : There is something wrong in this


application to print how many characters in the input. I don't know


what is wrong! someone help me...*/


//


#include "stdafx.h"





int main(void)


{


long nc;





nc = 0;


while (getchar() !=EOF)


++nc;


printf("%ld\n", nc);


}

Program does not work the way specified in C (read the Comment)?
getchar() may be a macro.





The program works fine in my system (though after replacing stdafx.h with stdio.h so it runs in my Linux console), but when I do things like that I do the following:





/* ... */


int main()


{


long nc;


int ch;


nc = 0;


ch=getchar();


while(ch!=EOF) {


++nc;


ch=getchar();


}


printf("%ld\n", nc);


}
Reply:This is plain gibberish!





Uninstall and re-install your program.





Cheers
Reply:I managed to get this to compile (Gentoo, current version, using GCC). However I changed the header files





You don't need stdafx.h, but you do need both stdio.h and stdlib.h. ie





#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


No comments:

Post a Comment