#include <stdio.h>
#include <stdlib.h>
main()
{
double ne;
for ( ne=0; getchar() != EOF; ++ne)
;
printf("%.0f\n", ne);
system("pause");
}
Hi, accorging to the book about C programming this code should print the number of characters in program's input, but it does nothing, can anybody help?
program from book doesn't work
Started by thatsme, Feb 11 2010 02:23 AM
7 replies to this topic
#1
Posted 11 February 2010 - 02:23 AM
|
|
|
#2
Posted 11 February 2010 - 02:54 AM
It works, just not with console input. You need to pipe a file to the app: ie: if you have compiled to "count.exe" then this will return the size of test.txt:
Although, its a silly way of getting the size of a file.
PS: remove the system() command. it isn't required and somewhat non-portable.
count.exe < test.txt
Although, its a silly way of getting the size of a file.
PS: remove the system() command. it isn't required and somewhat non-portable.
#3
Posted 11 February 2010 - 12:00 PM
thatsme said:
#include <stdio.h>
#include <stdlib.h>
main()
{
double ne;
for ( ne=0; getchar() != EOF; ++ne)
;
printf("%.0f\n", ne);
system("pause");
}
Hi, accorging to the book about C programming this code should print the number of characters in program's input, but it does nothing, can anybody help?
#include <stdlib.h>
main()
{
double ne;
for ( ne=0; getchar() != EOF; ++ne)
;
printf("%.0f\n", ne);
system("pause");
}
Hi, accorging to the book about C programming this code should print the number of characters in program's input, but it does nothing, can anybody help?
What book teachs main() (with no type) and system() ?
#4
Posted 11 February 2010 - 12:14 PM
outsid3r said:
What book teachs main() (with no type) and system() ?
I too, was taught main with no type when I was learning C. I was told it was only neccesary for C++
#5
Posted 11 February 2010 - 01:10 PM
*sigh* I wish it weren't so. The unadorned main is pre-ANSI-C. That was 1989. :(
#6
Posted 11 February 2010 - 11:31 PM
Must be one very old book covered in the stains of a thousand hippie coders
Buzz PHP Class Library - Web Components Made Easy!
http://www.buzzphp.com/
http://www.buzzphp.com/
#7
Posted 12 February 2010 - 12:09 AM
Most of the new compilers wont work if you put
" main() { printf("Hello world"); } "
You would require to put int main() or void main().
" main() { printf("Hello world"); } "
You would require to put int main() or void main().
#8
Posted 12 February 2010 - 12:10 AM
Oh and avoid using system, Because it will pause the program, go to the command prompt, search for that command then input it, use getchar() instead


Sign In
Create Account


Back to top









