#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;
}