day1IO作业

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
	int sum=0;
	FILE* fp=fopen(argv[1],"r");
	if(argc!=2)
	{
		return 1;
	}
	while(1)
	{
		int res=fgetc(fp);
		if(res==-1)break;
		else if(res=='\n')
		{
			sum++;
		}
	}
	printf("sum=%d\n",sum);
	fclose(fp);
	return 0;
}
ubuntu@ubuntu:~/IO/3.28$ 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef int datatype;
typedef struct node
{
	union
	{
		int len;
		int age;
	};
	char *name;
	struct node*next;
}link,*link_p;
link_p creat_H()
{
	link_p H=(link_p)malloc(sizeof(link));
	if(NULL==H)
	{
		printf("空间申请失败\n");
		return NULL;
	}
	H->len=0;
	H->next=NULL;
	return H;
}
link_p creat_new_point(char* name,int age)
{
	link_p new=(link_p)malloc(sizeof(link));
	if(NULL==new)
	{
		printf("空间申请失败\n");
		return NULL;
	}
	new->age=age;
	new->name=name;
	return new;
}
void insert_head(int age,char* name,link_p H)
{
	if(NULL==H)
	{
		printf("入参为空\n");
		return;
	}
	link_p new = creat_new_point(name,age);
	new->next=H->next;
	H->next=new;
	new->age=age;
	new->name=name;
	H->len++;
}
//void show(link_p H)
void show(link_p H)
{
	FILE* fp=fopen("./list.c","w");
	if(NULL==H)
	{
		printf("入参为空\n");
		return;
	}
	link_p p=H->next;
	while(p!=NULL)
	{
		fprintf(fp,"姓名%s,年龄%d\n",p->name,p->age);
		printf("%s,%d\n",p->name,p->age);
		p=p->next;
	}
	fclose(fp);
}
void show_H(link_p H)
{
	if(NULL==H)
	{
		printf("入参为空\n");
		return;
	}
	link_p p=H->next;
	while(p!=NULL)
	{
		printf("%s,%d\n",p->name,p->age);
		p=p->next;
	}
}
int main(int argc, const char *argv[])
{
	FILE* fp1=fopen("./list1.c","w");
	if(fp1==NULL)
	{
		return 1;
	}
	link_p H=creat_H();
	//insert_head("zhansan",20,H);
	//insert_head("lisi",19,H);
	//insert_head("wangwu",18,H);
	//show(H);
	fclose(fp1);
	FILE* fp2=fopen("./list2.c","r");
	if(fp2==NULL)
	{
		return 1;
	}
	while(1)
	{
#if 1
		char name[32];
		int age=0;
		int res=fscanf(fp2,"%s",name);
		if(res==-1)break;
		fscanf(fp2,"%d\n",&age);
		insert_head(name,age,H);
#endif
	}
	show_H(H);
	fclose(fp2);
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值