/*source: stralloc.c*/
#include <stdio.h>
#include <stdlib.h>
int main(void){
char *A;
int max=0;
//need to add error-checking
printf("enter max string length: ");
scanf("%d",&max);
while ((getchar())!='\n');
A=(char *)malloc(max+1); //room for \0
printf("enter string: ");
fgets(A,max,stdin);
printf("Third char is: %c\n",*(A+2));
//printf("Third char is: %c\n",A[2]));
exit(0);
}
I got this code from my class, but there is one part I don't understand. What does while ((getchar())!='\n');
do in this function?
Can anyone explain it to me?