- 论坛徽章:
- 0
|
题目大意如下:
有一段文本,比如
this is the first line.
another line.
another line.
another line.
another line.
another line.
still more.
Almost done now---.
Almost done now---.
another line.
still more.
finished.
如果有重复的两行,那么需要打印这两行。
another line.
Almost done now---.
其余不需要打印。
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "../type.h"
- int
- main ( int argc, char *argv[] )
- {
- FILE *pfFile = NULL;
- int iCh;
- int i;
- char acRead[MAX_DATA_LEN];
- char acStore[MAX_DATA_LEN];
- char acPrint[MAX_DATA_LEN];
- if (NULL == (pfFile = fopen("a.txt","rw")))
- {
- printf("can't open file\n");
- return EXIT_FAILURE;
- }
-
- while (EOF != (iCh = getchar()))
- {
- i = 0;
- strncpy(acStore, acRead, MAX_DATA_LEN);
- strncpy(acPrint, acRead, MAX_DATA_LEN);
- while('\n' != (iCh = getchar()))
- {
- acRead[i] = iCh;
- i++;
- }
- printf("%s\n", acRead);
- if (0 != strcmp(acRead, acStore)
- && 0 != strcmp(acRead, acPrint))
- {
- printf("%s \n", acRead);
- strncpy(acPrint, acRead, MAX_DATA_LEN);
- }
- }
- return EXIT_SUCCESS;
- } /* ---------- end of function main ---------- */
复制代码
a.txt 如下
this is the first line.
another line.
another line.
another line.
another line.
another line.
still more.
Almost done now---.
Almost done now---.
another line.
still more.
finished.
为什么我每次用gdb调试,第一个字符总是‘s’,然后就跳到了printf("%s\n", acRead);这条语句。其中的某一行根本没有读取? |
|