Reading a single character in C

前端 未结 5 603
攒了一身酷
攒了一身酷 2020-11-29 09:27

I\'m trying to read a character from the console (inside a while loop). But it reads more than once.

Input:

a

Output:



        
5条回答
  •  孤独总比滥情好
    2020-11-29 10:18

    you can do like this.

    char *ar;
    int i=0;
    char c;
    while((c=getchar()!=EOF)
       ar[i++]=c;
    ar[i]='\0';
    

    in this way ,you create a string,but actually it's a char array.

提交回复
热议问题