简体   繁体   中英

Reading from a textfile into an array into the C programming language

How do I read into an array a string with space in it, delimited with semicolons from a textfile in the C programming language?

***from textfile***
"My Record; My Second Record; My Third"

. . .

    fopen ...
    for(i = 0; i < 3; i++) {
    fscanf_s(myFile, "%s", myRecords[i].title); /* this want read the records */
    }
    fclose...

最明显的可能性是使用scanset转换:

fscanf_s(myFile, "%[^;]", myRecords[i].title);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM