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';
Printable View
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
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';
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
how can i recieve EOF in the running of a program?
or in the string input part??
Can you actually read? I am having my doubts here...
You only seem to notice what you want and ignore everything else...