【发布时间】:2016-02-15 03:10:16
【问题描述】:
我有一个如下所示的文件:
5
x=
6
y=
我想最初跳过第一行,解析第二行,然后回到第一行并 strcat 两个字符串。但是,我似乎无法正常工作。
例如:
我有:
while(fgets(buffer,sizeof(buffer),file) != NULL) {
fgets(buffer,100,file); //skip first line
char * tempVar = malloc(sizeof(char)*10);
strcpy(tempVar,buffer); //copy second line into tempVar
rewind(file); //go back to first line? doesnt work
//then strcat the two strings, so I get x=5
}
请注意,我的文件中的行并不总是这么简单,这些只是我尝试测试的示例行(在行之间返回和第四行,提前阅读等)。
有什么想法吗?
【问题讨论】: