c语言读取跳过注释,键盘输入Abc显示Bin\abc.exe,其他的也是一样的,求代码

如题所述

#include <stdio.h>

#include <string.h>


int main()

{

FILE *fp = NULL;

char find[20] = {0};

char str[200] = {0};


gets(find);


if ((fp=fopen("data.txt","r"))==NULL)

{

printf("Open data.txt failed!\r\n");

return 1;

}

while (fgets(str,sizeof(str),fp))

{

if ('#'==str[0])

{

continue;

}else

{

if (strncmp(find,&str[1],strlen(find))==0)

{

while (fgets(str,sizeof(str),fp))

{

if (str[0]!='[')

{

printf("%s",str);

}else

{

fclose(fp);

return 0;

}

}


}

}

return 0;

}

温馨提示:答案为网友推荐,仅供参考