how to tokenize string to array of int in c?

前端 未结 6 1622
暖寄归人
暖寄归人 2020-12-15 01:01

Anyone got anything about reading a sequential number from text file per line and parsing it to an array in C?

What I have in a file:

12 3 45 6 7 8
3         


        
6条回答
  •  盖世英雄少女心
    2020-12-15 01:40

    I'd strongly suggest NOT to use sscanf and friends when the number of fields is variable. Use strtok and atoi. Just make sure to read the strtok manpage well, many programmers I know find its syntax a bit surprising in the beginning. Also note that strtok will modify the input string, so you may want to work on a copy.

提交回复
热议问题