fscanf with colon (:) delimited data

后端 未结 1 357
情深已故
情深已故 2020-12-12 05:50

How do I fscanf this piece of data? There are no empty rows between the data and delimeter is a \':\'

VS1234567890654327:Rob Fordfi         


        
相关标签:
1条回答
  • 2020-12-12 05:55

    You can include the delimiters as part of your format to fscanf, like this:

    while (4 == fscanf(filename, "%[^:]:%[^:]:%d:%d", string[size], name[size], &number1[size], &number2[size])) {
        ...
    }
    

    Note the use of %[^:] format specifier. It says "any character except ':' is accepted". Also note that char* parameters are passed with no ampersand, because they are already pointers.

    Demo on ideone.

    0 讨论(0)
提交回复
热议问题