| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 629 人关注过本帖
标题:发一道题给大家做做!!
取消只看楼主 加入收藏
我菜119
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:938
专家分:1756
注 册:2009-10-17
结帖率:98.26%
收藏
已结贴  问题点数:20 回复次数:2 
发一道题给大家做做!!
编写一个程序,从文件中一行一行的读取文本,并完成如下任务:
如果文件中有两行或者是更多行相邻的文本内容相同,那么就打印出其中一行!你可以假定文件中的文本在长度上不会超过128个字符!!!

考虑下面对输入文件:
This is the first line.Another line.
And another.
And another.
And another.
And another.
Still more.
Almost done now --
Almost done now --
Another line.
Still more.
Finished!
输出的结果是:
This is the first line.Another line.
And another.
Still more.
Almost done now --
Another line.
Still more.
Finished!
搜索更多相关主题的帖子: first 
2010-10-20 11:20
我菜119
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:938
专家分:1756
注 册:2009-10-17
收藏
得分:0 
这是我自己写的代码,供大家参考一下:
程序代码:
# include <stdio.h>
# include <stdlib.h>
# include <string.h>

char string[300][130] ;

int
main()
{
    FILE *file_point ;
    char* pfile_name = "E:\\file.txt" ;
    int i , j ;
    if( ( file_point = fopen( pfile_name , "r") ) == NULL )
    {
        printf( "open error !\n" ) ;
        exit( EXIT_FAILURE ) ;
    }
    for( i = 0 ; !feof( file_point ) ; i++ )
    {
        fgets( string[i] ,sizeof( string[i] ) , file_point ) ;
    }
    for(j = 0 ; j < i ; j++ )
    {
        if( strcmp( string[j] , string[j + 1] ) == 0 )
            continue ;
        else
            puts( string[j] ) ;
    }
    return 0 ;
}

愿用余生致力编程
2010-10-20 13:41
我菜119
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:938
专家分:1756
注 册:2009-10-17
收藏
得分:0 
大家觉得这样的题很容易吗???不屑一做吗??悲哀呀!!!

愿用余生致力编程
2010-10-21 12:36
快速回复:发一道题给大家做做!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019242 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved