网站建设资讯

NEWS

网站建设资讯

c语言备份数据函数 cp命令

C语言求助。急急

#includeiostream.h

10多年的丰县网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整丰县建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“丰县网站设计”,“丰县网站推广”以来,每个客户项目都认真落实执行。

#includestring.h

#includefstream.h

#includeiomanip.h

class stu

{

char name[20];

double age,homephone,telphone;

char sex;

public:

stu(){}

stu(char n[20],char se,double ag,double ho,double te)

{

strcpy(name, n);

age=ag;

homephone=ho;

telphone=te;

}

friend void main();

};

void main()

{

cout"请选择您需要的操作!"endl;

cout"操作:"endl;

cout"(0)通讯录录入"endl;

cout"(1)增加人员"endl;

cout"(2)删除人员"endl;

cout"(3)修改数据"endl;

cout"(4)显示记录"endl;

cout"(5)退出"endl;

cout"选择相关操作请输入相对的括号里的阿拉伯数字!"endl;

stu *s[50];

int i=0;

int j=0;

bool flag2=0;

char p;

do

{

cinp;

if((p='0'p='5'))

flag2=1;

else

cout"指令错误!请重新输入:"endl;

}while(flag2==0);

switch(p)

{

case '0': //(0)通讯录录入

{

char name[20];

double age,homephone,telphone;

char sex,c;

do{

cout"请输入姓名:"endl;

cinname;

cout"请输入性别:"endl;

cinsex;

cout"请输入年龄:"endl;

cinage;

cout"请输入家里的电话号码:"endl;

cinhomephone;

cout"请输入移动电话号码:"endl;

cintelphone;

j++;

s[i]=new stu(name, sex, age, homephone , telphone);

i++;

cout"数据录入成功,想继续录入吗(y/n)"endl;

cinc;

flag2=0;

do

{

if(c!='y'c!='n')

{

cout"指令错误!请重新输入!"endl;

cinc;

}

else

flag2=1;

}while(flag2==0);

}while(c=='y');

break; }

////////////////////////////////////////////////////////////////////

case '1': //(1)增加人员(Add)

{

char name[20];

double age,homephone,telphone;

char sex,c;

do{

cout"请输入姓名:"endl;

cinname;

cout"请输入性别:"endl;

cinsex;

cout"请输入年龄:"endl;

cinage;

cout"请输入家里的电话号码:"endl;

cinhomephone;

cout"请输入移动电话号码:"endl;

cintelphone;

j++;

s[i]=new stu(name, sex, age, homephone , telphone);

i++;

cout"数据录入成功,想继续录入吗(y/n)"endl;

cinc;

flag2=0;

do

{

if(c!='y'c!='n')

{

cout"指令错误!请重新输入!"endl;

cinc;

}

else

flag2=1;

}while(flag2==0);

}while(c=='y');

break; }

case '2': //(2)删除人员(Delete)

{

char name[20];bool flag3=0;char c;

do{

cout"请输入您要删除的学生姓名:"endl;

cinname;

for(int h=0;hi;h++)

{

if(strcmp(name,s[h]-name)==0)

{

flag3=1;

i--;

do{

s[h]=s[h+1];

h++;

}while(h=i);

}

}

if(flag3==0)

cout"您要求删除的对象本来就不存在!请检查输入的正确性!";

cout"要继续删除吗?(y/n)"endl;

cinc;

if(c!='y'c!='n')

{

cout"指令错误!请重新输入!"endl;

cinc;

}

}while(c=='y');

break; }

case '3': //(3)修改数据(Alter)

{

char name[20],se;double ag,ho,te;flag2=0;

char c;

do

{

cout"请输入您要修改的学生的姓名:"endl;

cinname;

for(int h=0;hi;h++)

{

if(strcmp(name,s[h]-name)==0)

{

flag2=1;

cout"请输入性别:"endl;

cinse;

cout"请输入年龄:"endl;

cinag;

cout"请输入家里的电话号码:"endl;

cinho;

cout"请输入移动电话号码:"endl;

cinte;

s[h]-sex=se;

s[h]-age=ag;

s[h]-homephone=ho;

s[h]-telphone=te;

cout"数据修改成功!";

}

}

if(flag2==0)

{

cout"您要修改的学生本来就不存在!请检查重新输入!"endl;

}

cout"想继续修改吗(y/n)"endl;

cinc;

if(c!='y'c!='n')

{

cout"指令错误!请重新输入!"endl;

cinc;

}

}while(c=='y');

break; }

case '4': //(4)显示记录(List)

{

cout"本系统所有通讯录的数据如下:"endl;

if(i==0)

cout"管理系统中没有录入数据或者数据已经被删除!"endl;

for(int k=0;ki;k++)

{

coutk+1" ""姓名:"" "s[k]-name

"性别:"" "s[k]-sex"年龄:"" "s[k]-age

"家里的电话号码:"" "s[k]-homephone"移动电话号码:"

" "s[k]-telphoneendl;

}

break; } }

cout"您想继续进行其他操作吗?(y/n)"endl;

bool flag4=0;

do

{

cinp;

if(p!='y'p!='n')

cout"指令错误!请重新输入!"endl;

else

flag4=1;

}while(flag4==0);

if(p=='y')

cout"请输入操作代码(0 通讯录录入/1 增加人员(Add)/2 删除人员(Delete)/3 修改数据(Alter)/4 显示记录(List)/ 5 退出(Exit))"endl;

cinp;

for(int x=0;xi;x++)

{

delete s[x];

cout"删除所有成员!"endl;

}

}

回答者:little_goblin - 初入江湖 三级 7-11 09:35

评价已经被关闭 目前有 1 个人评价

100% (1) 不好

0% (0)

对最佳答案的评论 共 1 条

看不懂

评论者: hanrenhui88 - 试用期 一级

其他回答 共 1 条

我自己前不久编写的一个通讯录,呵呵.

#include"stdio.h"

#include"stdlib.h"

#include"string.h"

struct student

{

int no; /*学号*/

char name[20]; /*姓名*/

char acdamic[20]; /*院系*/

char major[20]; /*专业*/

char province[20]; /*籍贯*/

char address[40]; /*家庭地址*/

long phone; /*联系电话*/

struct student *next;

};

struct student *input();

void print(struct student *h);

struct student *insert(struct student *h);

struct student *del(struct student *h);

void find4(struct student *h);

void find3(struct student *h);

void find2(struct student *h);

void find1(struct student *h);

struct student *head=NULL;

char ch,*menu[]={"------------------通讯录菜单------------",

"1.----------建立学生通讯录---------------",

"2.----------输出全部学生通讯录---------------",

"3.----------增加的学生的个数---------------",

"4.----------删除指定学号的学生--------------",

"5.----------按系别查找学生信息-------------",

"6.----------按专业查找学生信息-------------",

"7.----------按姓名查找学生信息-------------",

"8.----------按学号查找学生信息--------------",

"9.----------退出通讯录-----------------------"};

struct student *input() /*输入函数*/

{

int n;

printf("请输入你要建立的学生通讯录的学生个数:\n");

scanf("%d",n);

struct student *h=NULL,*p,*q;

int i;

for(i=1;i=n;i++)

{

printf("请依次输入第%d个学生的学号,姓名,系别,专业,籍贯,家庭住址和联系电话:\n",i);

p=(struct student *)malloc(sizeof(struct student));

if(p==NULL)

{

printf("内存不足!\n");

exit(0);

}

scanf("%d%s%s%s%s%s%ld",p-no,p-name,p-acdamic,p-major,p-province,p-address,p-phone);

if(i==1)h=p;

else q-next=p;

q=p;

}

q-next=NULL;

return h;

}

void print(struct student *h) /*输出函数*/

{

struct student *p=h;

while(p)

{

printf("学生信息:\n%d,%s,%s,%s,%s,%s,%ld\n",p-no,p-name,p-acdamic,p-major,p-province,p-address,p-phone);

p=p-next;

}

}

struct student *insert(struct student *h) /*增加学生信息*/

{

int n;

printf("请输入你要增加的学生的个数:\n");

scanf("%d",n);

struct student *p,*r;

int i;

for(i=1;i=n;i++)

{

r=(struct student *)malloc(sizeof(struct student));

printf("请输入第%d个你要插入的学生的信息:\n",i);

scanf("%d%s%s%s%s%s%ld",r-no,r-name,r-acdamic,r-major,r-province,r-address,r-phone);

p=h;

h=r;

r-next=p;

}

return h;

}

struct student *del(struct student *h) /*按学号进行删除*/

{

int n;

printf("请输入要删除的学生的学号:\n");

scanf("%d",n);

struct student *p,*q;

if(h=NULL)printf("empty list!\n");

else

{

p=h;

while(p-no!=np-next)

{q=p;p=p-next;}

if(p-no==n)

{

if(h==p)h=p-next;

else q-next=p-next;

}

else printf("%d is not found!\n");

}

return h;

}

void find1(struct student *h) /*按院系查找学生信息*/

{

char s[40];

printf("请输入要查找的学生的院系:\n");

scanf("%s",s);

struct student *p;

if(h==NULL)printf("empty list!\n");

else

{

p=h;

while(p)

{

if(strcmp(p-acdamic,s)==0)

printf("学生信息:\n%d %s %s %s %s %s %ld\n",p-no,p-name,p-acdamic,p-major,p-province,p-address,p-phone);

p=p-next;

}

}

}

void find2(struct student *h) /*按专业查找*/

{

char s[20];

printf("请输入要查找的学生的专业名:\n");

scanf("%s",s);

struct student *p;

if(h==NULL)printf("empty list!\n");

else

{

p=h;

while(p)

{

if(strcmp(p-major,s)==0)

printf("学生信息:\n%d %s %s %s %s %s %ld\n",p-no,p-name,p-acdamic,p-major,p-province,p-address,p-phone);

p=p-next;

}

}

}

void find3(struct student *h) /*按姓名查找*/

{

char ss[10];

printf("请输入要查找的学生的姓名:\n");

scanf("%s",ss);

struct student *p;

if(h==NULL)printf("empty list!\n");

else

{

p=h;

while(p)

{

if(strcmp(p-name,ss)==0)

printf("学生信息:\n%d %s %s %s %s %s %ld\n",p-no,p-name,p-acdamic,p-major,p-province,p-address,p-phone);

p=p-next;

}

}

}

void find4(struct student *h) /*按学号查找*/

{

int num;

printf("请输入要查找的学生的学号:\n");

scanf("%d",num);

struct student *p;

if(h==NULL)printf("empty list!\n");

else

{

p=h;

while(p)

{

if(p-no==num)

printf("学生信息:\n%d %s %s %s %s %s %ld\n",p-no,p-name,p-acdamic,p-major,p-province,p-address,p-phone);

else

printf("没有你要查找的学生信息!\n");

p=p-next;

}

}

}

int menu_select()

{

int i,s;

char c[3];

for(i=0;i10;i++)

printf("%s\n",menu[i]);

do

{

scanf("%s",c);

s=atoi(c);

}while(s0||s9);

return s;

}

main()

{

for(;;)

{

switch(menu_select())

{

case 1:head=input();break;

case 2:print(head);break;

case 3:head=insert(head);break;

case 4:head=del(head);break;

case 5:find1(head);break;

case 6:find2(head);break;

case 7:find3(head);break;

case 8:find4(head);break;

case 9:exit(0);

}

}

}

c语言 save函数

可换成

void save()

{

char name[10];

FILE *fp;

int i;

scanf("%s",name)

if((fp=fopen(name,"wb"))==NULL)

{printf("cannot open file\n");

return;}

for(i=0;iMAX;i++)

if(fwrite(user[i],sizeof(struct diary_type),1,fp)!=1)

printf("file write error\n");

fclose(fp);

}

相关概念:

文件: 按一定规则存储在磁盘上的数据集合。

文件名: 能唯一标识某个磁盘文件的字符串。形式: 盘符:/ 路径 / 文件名.扩展名

文本文件:: 数据以其数字字符的ASCII码形式、一个字节一个字节地存储在磁盘上。

二进制文件:数据以二进制形式在存储在磁盘上。

设备文件:输入/输出设备

标准输入文件:键盘

标准输出文件/标准错误输出文件:显示器

文件型指针:C语言是通过名为FILE的结构型指针来管理文件读写的。FILE *变量名

文件的打开和关闭 :文件操作先建立文件与文件指针之间的关系,接着进行文件的读与写。建立文件与文件指针之间的联系的过程是文件的打开。终止这种联系就是文件的关闭

char ch;

ch = getchar () 功能等价于 ch = fgetc(stdin) 功能等价于 scanf("%c",ch) 功能等价于 fscanf(stdin, "%c",ch)

putchar(ch) 功能等价于 printf("%c",ch) 功能等价于 fputc(stdout) 功能等价于 fprintf(stdout, "%c", ch)

C语言常用词汇及函数有那些?

常用词汇:

1、short:修饰int,短整型数据,可省略被修饰的int。

2、long:修饰int,长整型数据,可省略被修饰的int。

3、long long:修饰int,超长整型数据,可省略被修饰的int。

4、signed:修饰整型数据,有符号数据类型。

5、unsigned:修饰整型数据,无符号数据类型。

6、restrict:用于限定和约束指针,并表明指针是访问一个数据对象的唯一且初始的方式。

7、return:用在函数体中,返回特定值(如果是void类型,则不返回函数值)。

8、continue:结束当前循环,开始下一轮循环。

9、break:跳出当前循环或switch结构。

10、goto:无条件跳转语句。

11、if:条件语句,后面不需要放分号。

12、else:条件语句否定分支(与if连用)。

13、switch:开关语句(多重分支语句)。

14、case:开关语句中的分支标记,与switch连用。

15、default:开关语句中的“其他”分支,可选。

常用函数:

1、int isalpha(int ch) 若ch是字母('A'-'Z','a'-'z'),返回非0值,否则返回0。

2、int isalnum(int ch) 若ch是字母('A'-'Z','a'-'z')或数字('0'-'9'),返回非0值,否则返回0。

3、int abs(int i) 返回整型参数i的绝对值。

4、double cabs(struct complex znum) 返回复数znum的绝对值。

5、double fabs(double x) 返回双精度参数x的绝对值。

6、long labs(long n) 返回长整型参数n的绝对值。

参考资料来源:百度百科—C语言

c语言文件备份!!!问题!!

fph=fopen("filenam","w");

这句不能这样写,应该改成:fph=fopen( filenam, "w" );

不然fopen总是打开文件名为"filenam"的文件,而不是数组filenam里面保存的文件名。

"filenam"这个名字没有后缀名,可能导致文件打开不成功,使得返回得到的文件指针fpq为NULL。

然后你判断的时候程序退出。


标题名称:c语言备份数据函数 cp命令
标题URL:http://cdweb.net/article/ddcojsi.html