【发布时间】:2014-07-22 01:01:56
【问题描述】:
我正在尝试让我的程序读取一个包含 2 列的文件,并且第一列包含一些字符串,我无法将其存储到数组中
这是我的代码:
fp2=fopen("Symbol Table.txt","r");char str[100];
while(fscanf(fp2,"%s %s",str,stemp[scnt])!=NULL) {
puts(stemp[scnt++]);getch(); //This is just here to display conents of second col
}
fclose(fp2)
这是我的 txt 文件:
void void
main Main
( Left Parenthesis
) Right Parenthesis
{ Left Brace
S Identifier
: Colon
$% Start of Block Comment
This program is a simple calculatorFuctions:ADD,SUB,MULT,DIV String
%$ End of Block Comment
Unsigned Noise Words
int Integer
存储长字符串的代码在进入数组之前被分割
【问题讨论】:
-
你需要使用
while(fscanf(fp2,"%s %s",str,stemp[scnt])==2) -
它仍然是相同的,其中的放入与之前相同的长字符串的某些部分仍存储在第二列数组中:(
-
试试
while(fscanf(fp2,"%s %[^\n]", str, stemp[scnt])==2) {