I was testing one of simple getchar() function on GNU compiler, but why not get expected output
mto@ubuntu:~/c$ ./a.out
agc
mto@ubuntu:~/c$
code as following :
#include <string.h>
#include "stdio.h"
#define MAX 80
int main()
{
char ch, buffer[MAX+1];
int x=0 ;
while ((ch =getchar() != '\n') && x<MAX)
buffer[x++]= ch;
buffer[x]= '\0';
int len = strlen(buffer);
for (int c=0; c< len; c++)
printf("%c" , buffer[c]);
return 0;
}
(ch = getchar() != '\n')should be(ch = getchar()) != '\n'. You assign the result of the comparison toch, but you want to assign the character.