菜鸟求教关于字符的问题
题是这样的:编一个程序,从标准输入一行一行的读取文本,并完成如下任务;如果文件中有两行或者更多行相邻的文本内容相同,那么就打印出其中一行,其余的行不多打印。(可以假设文件中的文本行在长度上不会超过128个字符)
下面是输入文件:
This is the first ilin.
Another ilin.
And another.
And another.
And another.
And another.
Still more.
Almost done now--
Almost done now--
Another line.
Still moer.
Finished!
小弟我自己编不出来,就参考了一下答案,可是把答案一字不落的抄到VC上还是不行,请各位大侠帮忙啊!!!
下面给一下答案的程序:
#include <stdio.h>
#define TRUE 1
#define FALSE 0
#define LINE_SIZE 129
void main()
{
char input[LINE_SIZE],previous_line[LINE_SIZE];
int printed_frome_group=FALSE;
if(gets(previous_line)!=NULL)
{
while(gets(input)!=NULL)
{
if(strcmp(input,previous_line)!=0)
{
printed_from_group=FLASE;
strcpy(previous_line,input);
}
else if(!printed_from_group)
{
printed_from_group=TRUE;
printf("%s\n",input);
}
}
}
}
诚心请教各位大侠!!
[解决办法]
看在你的结贴率的面子上我就随便说了,我不懂你程序的逻辑了。而且给我个输出sample吧
[解决办法]
本人菜鸟,正在看楼主的程序,已经晕了。
发现两个问题,其他的还没看出来。
1.缺少头文件<string.h>
2.
if(strcmp(input,previous_line)!=0){printed_from_group=FLASE; //写错了应该为FLASE
[解决办法]
晕!打错了
if(strcmp(input,previous_line)!=0){printed_from_group=FLASE; //写错了应该为FALSE