我的意思是說,我衹用vs2015中的C++,不用什麽“純C”,你不用vs的話,必須要做少量修改。
授人以渔,不授人以鱼。
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> const char* FileName = "Test1.txt"; int main(void) { FILE* file; char caption[81]; char lineText[512]; if (fopen_s(&file, FileName, "rt") == 0) { do { printf_s("\nInput the caption: "); } while (!gets_s(caption) || (caption[0] == '\0')); while (fgets(lineText, _countof(lineText), file)) { if (_strnicmp(lineText, caption, strlen(caption)) == 0) { printf_s("%s", lineText); } } fclose(file); } else { printf_s("File %s not found.\n", FileName); } printf_s("\nPress any key to continue..."); _getch(); return EXIT_SUCCESS; }
[此贴子已经被作者于2015-11-23 11:24编辑过]