【发布时间】:2014-10-15 09:15:28
【问题描述】:
我想从包含字符串数组的文件中提取不同的子字符串。我的文件与此类似。
abcdxxx
efghijkyyy
lmzzz
ncdslanclsppp
kdfmsqqq
cbskdnsrrr
我想从上面的文件中提取 xxx、yyy、zzz、ppp、qqq、rrr(基本上是最后 3 个字符)并存储到一个数组中。我引用了这个链接How to extract a substring from a string in C?,但觉得不可行,因为我文件中的内容是动态的,可能会在下次执行时发生变化。有人可以简要介绍一下吗? 这是我的方法
FILE* fp1 = fopen("test.txt","r");
if(fp1 == NULL)
{
printf("Failed to open file\n");
return 1;
}
char array[100];
while(fscanf(fp1,"%[^\n]",array)!=NULL);
for(i=1;i<=6;i++)
{
array[i] += 4;
}
【问题讨论】:
-
您的“方法”看起来像存根代码。到目前为止,您是否尝试过其他方法?