Sign in to follow this  

getchar() problem ...

This topic is 4868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

excuse me: while( exit_flag ==0 ) { printf("Enter a line of text "); ch = getchar(); while((ch!='\n') && (char_count<MAXBUFFERSIZE)) { buffer[char_count++] = ch; ch = getchar() } } can u help me explain the statement? does it mean the value of ch has been assigned to buffer[char_count++]? any replies are appreciated

Share this post


Link to post
Share on other sites
Quote:
Original post by mckoo
does it mean the value of ch has been assigned to buffer[char_count++]?


Basically what that does is that it assigns a character to your buffer then adds one to the counter after it assigns it. However, if you had something like buffer[++char_count] then it would add one to the counter and then assign it to your char array.

[Edited by - NullPointer33 on August 17, 2004 11:03:34 PM]

Share this post


Link to post
Share on other sites
I'm grateful to all replies, thx a lot~

so that means

buffer[char_count++] ====> get the character and add one to char_count after it is been assigned

buffer[++char_count] ===> adds one to the char_count and then assign the value?

buffer[char_count++] = ch;
ch = getchar();

as ch is not defined....let ch be assigned to buffer first, then the value of ch was been assigned also to buffer[char_count++] = ch; as well?

Share this post


Link to post
Share on other sites
Yes, first you grab a character from the input stream, then you move on to the loop assign a character to the buffer and add one to the counter. Then you grab the next character from the input stream and repeat until the while statement isn't true...Also don't forget to add the terminating character to the string '\0'

Share this post


Link to post
Share on other sites

This topic is 4868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this