//字符数组中存放太麻烦了,放在一个文件中好一点
#include<stdio.h>
#include<stdlib.h>
#define IN 1
#define OUT 0
int main()
{
char szFilename[256]
FILE *fp
printf("input the file:")
scanf("%s",szFilename)
if((fp=fopen(szFilename,"r"))==NULL)
{
printf("the file don't exist!")
exit(1)
}
int flag=OUT
int c
int nw=0
while((c=fgetc(fp))!=EOF)
{
if(c==' ')
{
flag=OUT
}
else if(OUT==flag)
{
flag=IN
nw++
}
}
printf("THe num is:%d\n",nw)
return 0
}
/*用C语言设计学生档案管理
1. 题目描述
编写一个程序来管理学生档案,系统能实现以下功能:
输入信息:学生信息的输入;
修改信息:对学生信息进行添加、删除与修改;
查询:能够根据学号或姓名查询某个学生的信息;
输出:输出所有学生信息或查询学生信息的结果。
2. 设计提示
1)先确定学生档案管理的数据结构。如每个学生信息:学号、姓名、性别、年龄、地址 ……等,每个数据项各用什么数据类型;
2)划分实现学生档案管理的功能模块:如主菜单、输入数据、修改、查询、输出等功能,并确定各功能模块的实现算法。
3)画出各模块的流程图或S-R图;
4)选择C语言的技术:普通数组、结构体数组、函数、指针、单链表或文件等。
5)编写程序代码。*/
#include<stdio.h>
#include<stdlib.h>
#include<string>
typedef struct student{
char ID[10]
char name[10]
char sex[3]
int age
char addr[30]
struct student *next
}stu
void Input(stu *&head)
{
stu *temp,*current
temp=(stu *)malloc(sizeof(stu))
printf("输入学生信息:\n")
printf("学号\t姓名\t性别\t年龄\t地址\t\n")
fflush(stdin)
scanf("%s%s%s%d%s",temp->ID,temp->name,temp->sex,&temp->age,temp->addr)
temp->next=NULL
if(head==NULL)
{head=(stu *)malloc(sizeof(stu))head->next=temp}
else
{
current=head->next
while(current->next)
current=current->next
current->next=temp}
printf("添加成功\n")
system("pause")
}
void FindByID(stu *&head)
{
if(head==NULL)
{printf("数据为空\n")
system("pause")return }
else
{stu *current =head->next
bool flag=0
char a[10]
printf("输入要查询的学号:\n")
fflush(stdin)
scanf("%s",a)
do
{
if(strcmp(current->ID,a)==0)
{flag=1break}
current=current->next
}while(current!=NULL)
if(flag)
{
printf("学号:%s 姓名:%s 性别:%s 年龄:%d 地址:%s\n",current->ID,current->name,current->sex,current->age,current->addr)
system("pause")
}
else
{
printf("没有找到\n")
system("pause")
}
}
}
void FindByName(stu *&head)
{
if(head==NULL)
{printf("数据为空\n")
system("pause")return }
else
{
stu *current =head->next
bool flag=0
char a[10]
printf("输入要查询的姓名:\n")
fflush(stdin)
scanf("%s",a)
do
{
if(strcmp(current->name,a)==0)
{flag=1break}
current=current->next
}while(current!=NULL)
if(flag)
{
printf("学号:%s 姓名:%s 性别:%s 年龄:%d 地址:%s\n",current->ID,current->name,current->sex,current->age,current->addr)
system("pause")
}
else
{
printf("没有找到\n")
system("pause")
}
}
}
void Delete(stu *&head)
{
if(head==NULL)
{printf("数据为空\n")
system("pause")return }
else
{ stu *current =head->next
stu *prev=NULL
char a[10]
printf("输入要删除的学号:\n")
fflush(stdin)
scanf("%s",a)
while(current!=NULL)
{
if(strcmp(current->ID,a)==0)break
prev=current
current=current->next
}
if(prev==NULL)
{head->next=current->nextfree(current)}
else
{prev->next=current->next
free(current)}
printf("删除成功\n")
system("pause")
}
}
void Show(stu *&head)
{
stu *current =head->next
if(current==NULL)
{printf("数据为空\n")
system("pause")return }
printf("学号\t姓名\t性别\t年龄\t地址\t\n")
while(current!=NULL)
{
printf("%s\t%s\t%s\t%d\t%s\n",current->ID,current->name,current->sex,current->age,current->addr)
current=current->next
}
system("pause")
}
void Modify(stu *&head)
{
if(head==NULL)
{printf("数据为空\n")
system("pause")return }
bool flag=0
char a[10]
printf("输入要查询的学号:\n")
fflush(stdin)
scanf("%s",a)
stu *current=head->next
do
{
if(strcmp(current->ID,a)==0)
{flag=1break}
current=current->next
}while(current!=NULL)
if(flag)
{
printf("学号:%s 姓名:%s 性别:%s 年龄:%d 地址:%s\n",current->ID,current->name,current->sex,current->age,current->addr)
printf("请重新输入该学生信息:\n")
printf("学号\t姓名\t性别\t年龄\t地址\t\n")
scanf("%s%s%s%d%s",current->ID,current->name,current->sex,&current->age,current->addr)
printf("修改成功\n")
printf("pause")
}
else
{
printf("没有找到\n")
system("pause")
}
}
void Print()
{
system("cls")
printf("请选择功能(按0退出)\n")
printf("1------添加学生\n")
printf("2------通过学号查询学生\n")
printf("3------通过姓名查询学生\n")
printf("4------删除学生\n")
printf("5------修改学生\n")
printf("6------显示所有学生\n")
}
int main()
{
char ch
stu *head=NULL
do
{
Print()
fflush(stdin)
ch=getchar()
//system("cls")
switch(ch)
{
case '1':Input(head)break
case '2':FindByID(head)break
case '3':FindByName(head)break
case '4':Delete(head)break
case '5':Modify(head)break
case '6':Show(head)break
}
}while(ch!='0')
}