#include <stdio.h>
#include <string.h>
void main()
{
int i,n;
char str[500];
FILE *fp;
printf("请输入需要读取第几行数据\n");
scanf("%d", &n);
if((fp=fopen("test.txt","rt"))==NULL) /* 假设在程序目录下,文件名为test.txt */
{
printf("cannot open file\n");
return;
}
for(i=1;i<n;i++)
fscanf(fp,"%*[^\n]%*c"); /* 跳过一行
字符串 */
fscanf(fp,"%[^\n]%*c",str);/* 读入一行字符串 */
printf("%s\n", str);
fclose(fp);
}