首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

初学者请问关于字符的有关问题!

2012-02-29 
菜鸟请教关于字符的问题!!之前发了贴,有人提示我是少了个头文件,我就试了试,结果一时小兴奋,还是不行,结贴

菜鸟请教关于字符的问题!!
之前发了贴,有人提示我是少了个头文件,我就试了试,结果一时小兴奋,还是不行,结贴早了,再发出来请教!


题是这样的:编一个程序,从标准输入一行一行的读取文本,并完成如下任务;如果文件中有两行或者更多行相邻的文本内容相同,那么就打印出其中一行,其余的行不多打印。(可以假设文件中的文本行在长度上不会超过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>
#include <string.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);
}
}
}
}


诚心请教各位大侠!! 


[解决办法]

C/C++ code
#include <stdio.h>#include <string.h>#define TRUE 1#define FALSE 0#define LINE_SIZE 129int main(int argc,char*argv[]){    char input[LINE_SIZE],previous_line[LINE_SIZE];    int printed_from_group=FALSE;    if(gets(previous_line)!=NULL)    {        while(gets(input)!=NULL)        {            if(strcmp(input,previous_line)!=0)            {                printed_from_group=FALSE;                strcpy(previous_line,input);            }            else if(!printed_from_group)            {                printed_from_group=TRUE;                printf("%s\n",input);            }        }    }    return 0;}
[解决办法]
探讨
C/C++ code
#include <stdio.h>
#include <string.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=FA……

热点排行