we havent learned files
there is no End Of File in this program
can i change it into '\0'
or some like that?
Code:for (i = 0; i < 39 && (ch = getchar()) != '\n' && ch != EOF; ++i) { input2[i] = ch; } input2[i] = '\0';
we havent learned files
there is no End Of File in this program
can i change it into '\0'
or some like that?
Code:for (i = 0; i < 39 && (ch = getchar()) != '\n' && ch != EOF; ++i) { input2[i] = ch; } input2[i] = '\0';
What?!
The current code will change the last valid character into NUL. Not what you want, infact you don't want anything.
i want to keep this loop doing what it does but
without EOF
It already does... perhaps brush up on your loops.
so i can delete this EOF condition?
No... because the condition stops you from putting EOF in the array.
getchar() returns EOF on *error* or when it reaches the EOF.
So getchar() will return EOF, even if there *is* no EOF char at the end of the file!
So I believe you will want to keep EOF just where it is, in your for statement.
Can you show the input that the for statement is not handling right?
this loop works fine
but i cant use the term EOF
i am looking for a way to replace it
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
is there a way to state EOF in getchar() terms
like
Code:for (i = 0; i < 39 && (ch = getchar()) != '\n' && ch !=(getchar error); ++i) { input2[i] = ch; } input2[i] = '\0';
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
What will happen if i will remove this EOF condition regarding the string??
will it stop putting chars into the string and put '\0' like before
In most situations NOTHING will change. However, if you happen to receive an EOF, it will continue to fill the string with EOF (converted to a character). And unless some part of your code detects and exits (or does something else meaningful) on EOF, it will loop forever.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
how can i recieve EOF in the running of a program?
or in the string input part??