更新时间:2023-11-22 13:07:34
假设你有:
char string1[20];
char string1[20];
int intA;
你可以这样做:
fscanf(file, "%19[^,],%19[^,],%d\n", string1, string2, &intA);
%[^,]
读的非逗号字符的字符串,并在第一个逗号停止。 19
是一个字符阅读(假设20的缓冲大小),因此您不必缓冲区溢出的最大数量。
%[^,]
reads a string of non-comma characters and stops at the first comma. 19
is the maximum number of characters to read (assuming a buffer size of 20) so that you don't have buffer overflows.