I'm trying to write a while loop in two different ways and noticed that using ',' in the condition twice doesn't work the way I think it does. I'm just curious about what actually happens. Here's the code :
#include <stdio.h>
int main()
{
int i = 0, lim = 1000, c;
char s[lim];
while (i < lim - 1, (c = getchar()) != '\n')
{
if (c != EOF)
{
s[i] = c;
}
else
{
break;
}
++i;
}
printf("%s\n", s);
return 0;
}
#include <stdio.h>
int main()
{
int i = 0, lim = 1000, c;
char s[lim];
while (i < lim - 1, (c = getchar()) != '\n', c != EOF)
{
s[i] = c;
++i;
}
printf("%s\n", s);
return 0;
}