Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions chapter_2/exercise_2_02/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,25 @@
int main(void)
{
char s[MAXLINE];

// int i;
// int c;
// for (i = 0; (i < MAXLINE - 1) * ((c = getchar()) != '\n') * (c != EOF); ++i)
// {
// s[i] = c;
// }

int i = 0;
int loop = 1;
while (loop)
{
char c = getchar();

if (i >= (MAXLINE - 1) || c == '\n' || c == EOF)
{
loop = 0;
int c, i = 0;

while (1){
if (i >= MAXLINE - 1)
break;

c = getchar();

if (c == '\n')
break;
else if (c == EOF)
break;
else
s[i++] = c;
}
s[i] = '\0';

s[i++] = c;
}

s[i] = '\0';
printf("%s\n", s);

printf("%s", s);

return 0;
}
Expand Down