#include <stdio.h>
#include <string.h>
int main()
{
int i,n,bai=1, line=0, len=0,j, num=0;
char buf[10], buf1[1000], ch=1;
FILE* fa;
FILE* fb;
FILE* fc;
if((fb = fopen("b.txt", "r")) == NULL)
{
printf("open fb fail =====>>>\n");
return -1;
}
if((fc = fopen("c.txt", "w")) == NULL)
{
printf("open fc fail =====>>>\n");
return -1;
}
if((fa = fopen("a.TXT", "r")) != NULL)
{
while(fgets(buf, 10, fa) != NULL)
{
n = strlen(buf);
for(i=0; i<n; i++)
{
if(buf[i]<= '9' && buf[i] >= '0')
len++;
}
for(j=0; j<len; j++)
{
line += (buf[len-j-1]-'0')*bai;
bai*=10;
//printf("line =%d", buf[len-j-1]-'0');
}
while(ch != EOF)
{
ch =fgetc(fb);
if(ch == '\n')
{
num++;
if(num == (line-1))
{
printf("line:%d\n", num);
fgets(buf1, 1000, fb);
fwrite(buf1, strlen(buf1)+1, 1, fc);
fputc('\n', fc);
break;
}
}
}
fseek(fb, 0, SEEK_SET);
memset(buf, 0, sizeof(buf));
ch = 1;
num= line = len =0;
bai=1;
}
}
fclose(fa);
fclose(fb);
fclose(fc);
return 0;
}
参考下吧