I'm writing a program that needs to read input one character at a time and transform that input, and I need to be able to differentiate the end of a line (\n) and the end of the stdin. For whatever reason my program just loops infinitely after it gets to the last line and never prints it. I'm wondering why it's never catching EOF? I took out some of the code from the bottom because it's just a ton of if statements replacing characters with uppercase characters and such. I basically just don't understand why my code is never breaking.
#include <stdio.h>
#include <string.h>
int main(void)
{
int MAXCHARS = 79;
int curr;
char currline[MAXCHARS*2];
char lastline[MAXCHARS*2];
memset(currline,0,158);
memset(lastline,0,158);
int pointer = 0;
while (1)
{
curr = getchar();
if (curr == EOF)
{
for (int i = 0; i < pointer; i++)
{
printf("%c", currline[i]);
}
break;
}
if (curr == '\n')
{
if (currline == lastline)
{
pointer = 0;
}
else
{
strcpy(lastline,currline);
for (int i = 0; i < pointer; i++)
{
printf("%c", currline[i]);
}
pointer = 0;
}
}
}
}