fscanf return value

前端 未结 5 428
孤街浪徒
孤街浪徒 2021-01-12 02:05

What does fscanf return when it reads data in the file. For example,

int number1, number2, number3, number4, c;

c = fscanf (spFile, \"%d\", &number1);
/         


        
5条回答
  •  隐瞒了意图╮
    2021-01-12 02:37

    I quote from cplusplus.com .

    On success, the function returns the number of items of the argument list successfully filled. This count can match the expected number of items or be less (even zero) due to a matching failure, a reading error, or the reach of the end-of-file.

    If a reading error happens or the end-of-file is reached while reading, the proper indicator is set (feof or ferror). And, if either happens before any data could be successfully read, EOF is returned.

    --EDIT--

    If you are intention is to determine the number of bytes read to a string.

    int bytes;
    char str[80];
    fscanf (stdin, "%s%n",str,&bytes);
    printf("Number of bytes read = %d",bytes);
    

提交回复
热议问题