用C实现文件readLine函数
来源:互联网 发布:vue项目案例 知乎 编辑:程序博客网 时间:2024/05/19 17:08
/ ReadWord.cpp.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "stdio.h"#include "stdlib.h"#define MAX 64bool readword(FILE *fp,char words[]){ if(fp==NULL) { puts("The file is not exist!"); return false; } if(feof(fp)) { puts("The end of the file!"); return false; } *words='\0'; char vChar=getc(fp); while(vChar!=EOF&&vChar!='\n') { *(words++)=vChar; *words='\0'; vChar=getc(fp); } return true;}int _tmain(int argc, _TCHAR* argv[]){ FILE *fp; char words[MAX]; int i=1; /* //used to create file content if ((fp = fopen("testFile", "a+")) == NULL) { fprintf(stdout,"Can't open \"testFile\" file.\n"); exit(1); } puts("Enter words to add to the file; press the Enter key at the beginning of a line to terminate."); while (gets(words) != NULL && words[0] != '\0') fprintf(fp, "%s ", words); puts("File contents:"); rewind(fp); /// go back to beginning of file while (fscanf(fp,"%s",words) == 1) puts(words);*/ if((fp=fopen("testFile","r"))==NULL) { fprintf(stdout,"Can't open \"testFile\" file.\n"); exit(1); } while(readword(fp,words)) { printf("Line %d:",i++); puts(words); } rewind(fp); if (fclose(fp) != 0) fprintf(stderr,"Error closing file\n"); return 0;}
0 0
- 用C实现文件readLine函数
- readline函数实现源码
- c语言 readline实现
- 8. readline函数的实现
- c语言readline的实现
- 用C语言实现类似于JAVA readLine()的功能
- 用java内存映射实现读取文件行(readline)
- recv函数和readline实现思想
- readline函数
- 【Python】Learn Python the hard way, ex20 用函数读文件readline
- 编译lua.c:80:31: fatal error: readline/readline.h: 没有那个文件或目录
- python中读取文件函数read()、readline()、readlines()的区别
- 小白学c++之TCP readline的实现和函数封装
- Pro_4_UNIX下高效readline函数的实现_2016_08_10
- 关于Readline函数
- readline及freadline函数
- readn,writen,readline函数
- python readline()函数
- ecshop二次开发新发现(一)
- FMDB 简介
- Java创建文件夹及文件
- IIS7 HTTP.sys漏洞深入分析
- ZOJ 2836 Number Puzzle (容斥原理)
- 用C实现文件readLine函数
- priority_queue 用法详解
- 实验四:Linux常用命令
- new/delete 和malloc/free 的区别一般汇总
- java导出excel java操作文件、文件夹 java制作zip
- ACM常用定理
- JavaMail开发
- 负能量爆棚
- 总结