• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

wchenfeng

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

文件,本程序用于创造一个file.csv文件,或者搜索一个file.csv文件,然后输入字符串到其中,并进行读取

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define nu NULL
int main()
{
	FILE *fp;
	char string[81];
	if((fp=fopen("file1.csv","w"))==nu)
	{
		printf("cannot open this file");
		exit(0);
	}
	while(strlen(gets(string))!=nu)
		{
			fputs(string,fp);
			fprintf(fp,"\n");
	}
	fclose(fp);
	if((fp=fopen("file1.csv","r"))==nu)
	{
		printf("cannot open this file");
		exit(0);
	}
	else {
		while(fgets(string,18,fp)!=nu)
		{
			printf("%s",string);
		}
		fclose(fp);
	}
}

posted on 2022-04-12 20:03  王陈锋  阅读(15)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3