E
Enrico `Trippo' Porreca
Both K&R book and Steve Summit's tutorial define a getline() function
correctly testing the return value of getchar() against EOF.
I know that getchar() returns EOF or the character value cast to
unsigned char.
Since char may be signed (and if so, the return value of getchar() would
be outside its range), doesn't the commented line in the following code
produce implementation-defined behaviour?
char s[SIZE];
int c;
size_t i = 0;
while ((c = getchar()) != EOF && c != '\n' && i < SIZE - 1) {
s = c; /* ??? */
i++;
}
s = '\0';
If this is indeed implementation defined, is there any solution?
correctly testing the return value of getchar() against EOF.
I know that getchar() returns EOF or the character value cast to
unsigned char.
Since char may be signed (and if so, the return value of getchar() would
be outside its range), doesn't the commented line in the following code
produce implementation-defined behaviour?
char s[SIZE];
int c;
size_t i = 0;
while ((c = getchar()) != EOF && c != '\n' && i < SIZE - 1) {
s = c; /* ??? */
i++;
}
s = '\0';
If this is indeed implementation defined, is there any solution?