-
Probably truncation somewhere inside the loop.
The problem is that getchar()'s return value can either be EOF, or inside the domain of a char. If it's EOF and you assign to a char, you lose that information, and either the loop won't terminate or it might terminate on a regular char as well.
You should do it like this:
Code:
int t;
while((t = getchar()) != EOF) {
char c = (char)t;
// ...
}
Inside the loop, t must be in the domain of a char, so the cast is safe, and making it explicit prevents compiler warnings.
-
The compiler warning had to do with the default case inside the loop.
Changing to c to int produced produced a warning that argument 2 of strncat was being called with an incompatible pointer type. This didn't seem to affect the working of the program, but I do take warnings as a sign I should be doing something differently.
I changed to the code above and all is well. Thanks for the tip.
-
Propably in strncat. You have to cast c to a char and then take its address.