I dont get this:
c=getchar(). where c is an integer type. so getchar takes the input from a file or keyboard and put it into a numerical variable. how that? what does this function return? the ascii code for the input?
I dont get this:
c=getchar(). where c is an integer type. so getchar takes the input from a file or keyboard and put it into a numerical variable. how that? what does this function return? the ascii code for the input?
The getchar() function returns the next character from stdin. The character is read as an unsigned char that is converted to an integer.
If the end of the file is reached, getchar() returns EOF. If an error is encountered, EOF is also returned.
The getchar() function is often implemented as a macro.
NEVER PET YOUR DOG WHILE IT'S ON FIRE!
The reason why it returns an int is because of EOF. It's value is 32 bits and is 0xffffffff if i'm not mistaken. If you were to do something like:
char c;
c = getchar();
if(c == EOF)
This would be wrong. You would not know if you were getting the character 0xff or EOF since you shoved the value into a char. Check the return value as an int. If it's not EOF, treat it as a char.
Try not.
Do or do not.
There is no try.
- Master Yoda
Ok. Now another problem linked to strings. I read a string into a array of char and want to count the letters. i put the !='\0' condition in a while statement but still, when i type space it stop counting what i write after. It was supposed to stop counting when it got to end, means found '\0'. Some ideas? I still have none.
Thank u.
Post some code.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]