reading multiple variable types from single line in file C

后端 未结 5 1206
无人及你
无人及你 2021-01-27 14:09

Alright I\'ve been at this all day and can\'t for the life of me get this down, maybe you chaps can help. I have a file that reads as follows

1301,1055150

5条回答
  •  遥遥无期
    2021-01-27 14:33

    I have a question for you... If you want to know how to use a diamond cutter, do you try it and see, or do you consult the manual? The problem here isn't the result of your choice, but your choice itself. Believe it or not, I have answered these questions so often that I'm tired of repeating myself. The answer is all in the manual.

    Read the POSIX 2004 scanf manual — or the POSIX 2008/2013 version — and the answer this question and you'll have some idea of what you're not doing that you should be. Even fscanf code should use assert as a debugging aid to ensure the number of items read was correct.

    %[^,]s It seems as though there's a mistake here. Perhaps you meant %[^,]. The %[ format specifier is a different format specifier to the %s format specifier, hence in the presumably mistaken code there are two directives: %[^,] and s. The s directive tells scanf to read an 's' and discard it.

提交回复
热议问题