Using scanf to read in certain amount of characters in C?

后端 未结 4 870
Happy的楠姐
Happy的楠姐 2021-01-03 13:06

I am having trouble accepting input from a text file. My program is supposed to read in a string specified by the user and the length of that string is determined at runtime

4条回答
  •  感情败类
    2021-01-03 13:43

    You can also use fread, where you can set a read limit:

    char string[5]={0};
    if( fread(string,(sizeof string)-1,1,stdin) )
      printf("\nfull readed: %s",string);
    else
      puts("error");
    

提交回复
热议问题