5、按行读取文件中的内容,并输出长度最大的行
来源:互联网 发布:抓取数据的免费软件 编辑:程序博客网 时间:2024/05/17 07:19
从test.txt中按行读取内容,然后比较输出最大长度的行。思路很简单,直接读程序即可,测试输出是可用的。
#include <stdio.h>#include <string.h> #define MAXLEN 100int main(int argc, char* argv[]){FILE* fp;char MaxBuf[MAXLEN];char buf[MAXLEN];int maxlenth=0, templenth=0;char c;fp = fopen("test.txt", "r");while((templenth=getlines(fp, buf, MAXLEN)) > 0){if(templenth > maxlenth){maxlenth = templenth;copy(MaxBuf, buf, maxlenth+1);}printf("%s", buf);}printf("MAXLEN:%d\t%s", maxlenth, MaxBuf);}int getlines(FILE* fp, char* buffer, int maxlen){int nl=0;char c=0;while(((c=getc(fp)) != EOF) && (c != '\n') && (nl<maxlen-1)){buffer[nl++] = c;}if(c == '\n')buffer[nl++] = c;buffer[nl] = '\0';return nl;}int copy(char to[], char from[], int lenth){int i;for(i=0;i<lenth; i++)to[i] = from[i];}
- 5、按行读取文件中的内容,并输出长度最大的行
- java按行读取文件内容并输出
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- shell读取文件夹里的文件内容并输出
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- InputStream 读取文件并输出内容
- NIO按行读取文件内容,并打印出来
- java按行读取文件并输出到控制台
- 利用stringstream将文件中的内容一行行读取并输出出来
- Java_IO流_按行读取文本文件的内容并按行写入到另一文件
- Python 读取文件替换其中的内容并输出到一个新的文件内
- 读取文件的每一行内容并输出 的shell脚本实现
- jquery ui dialog
- linux下如何统计一个目录下的文件个数以及代码总行数的命令
- 寂寞清秋怎敌寒
- 有网了!!!!!!!!!!!!!
- thinkphp中$think.get.tag系统模板变量乱码问题
- 5、按行读取文件中的内容,并输出长度最大的行
- 工作札记(一)
- 进制转换
- struts2 hibernate spring 所必需的包
- Redis SNAPSHOT的实现
- 实战android手机telnet、ftp登陆,权限修改
- 双向供给的教育,全面的战略眼光
- Date Difference
- Best Digital Signal Processing Books