| 202.116.20.* |
1楼 #include "stdio.h" #include "conio.h" struct qq { char num[12]; char name[10]; char age[2]; }Qq[1]; main() { int kk=1;char choice; loop2 : init(); loop : scanf("%c",&choice); switch(choice) { case 'n': case 'N': newf();break; case 'a': case 'A': break; case 'l': case 'L': system("cls");listf();getch();system("cls");goto loop2; case 'f': case 'F': findf();getch();goto loop2; case 'd': case 'D': deletef();getch();goto loop2; case 'q': case 'Q': return 0; default: goto loop; } while(kk==1) { addf(); printf("enter 1 to continue add.\n"); scanf("%d",&kk); system("cls"); } goto loop2; } int init() { printf("\n**************************************\n"); printf("******第一次用本程序请按n(new)********\n"); printf("*********增加记录请按a(add)***********\n"); printf("*******查看记录情况请按l(list)********\n"); printf("*****查询某个记录情况请按f(find)******\n"); printf("********删除记录请按d(delete)*********\n"); printf("***********退出请按q(quit)************\n"); printf("**************************************\n"); } int newf() { FILE *fp,*Fp; int n; Fp=fopen("QQ","w"); fclose(Fp); fp=fopen("num","w"); n=0; fprintf(fp,"%d",n); fclose(fp); } int addf() { FILE *fp1,*fp;int n; printf("**************************************\n"); printf("******请依次输入QQ号,姓名,年龄.*******\n"); printf("**************************************\n"); fp1=fopen("QQ","a"); scanf("%s%s%s",&Qq[0].num,&Qq[0].name,&Qq[0].age); fwrite(&Qq[0],sizeof(struct qq),1,fp1); fclose(fp1); fp=fopen("num","r"); fscanf(fp,"%d",&n); fclose(fp); fp=fopen("num","w"); n++; fprintf(fp,"%d",n); fclose(fp); } int listf() { FILE *fp;int n,i,k=0; fp=fopen("num","r"); fscanf(fp,"%d",&n); fclose(fp); fp=fopen("QQ","r"); for (i=0;i<n;i++) { fread(&Qq[0],sizeof(struct qq),1,fp); printf("QQ:%s\nname:%s\nage:%s\n\n\n",&Qq[0].num,&Qq[0].name,&Qq[0].age); k++; if (k%4==0) {printf("\nput any key continue\n"); getch();system("cls");k=0;} } fclose(fp); } int findf() { char namef[10];int n,i; FILE *fp; printf("\n*******请输入姓名********\n"); scanf("%s",&namef); fp=fopen("num","r"); fscanf(fp,"%d",&n); struct qq q[n]; fclose(fp); fp=fopen("QQ","r"); for (i=0;i<n;i++) { fread(&q[i],sizeof(struct qq),1,fp); if (strcmp(q[i].name,namef)==0) { printf("QQ:%s\nname:%s\nage:%s\n\n\n",q[i].num,q[i].name,q[i].age); fclose(fp); return 0; } } printf("sorry, the name can't be found.\n"); printf("put any key continue.\n"); fclose(fp); } int deletef() { char namef[10];int n,i,kk=-1; FILE *fp; printf("\n*******请输入要删除QQ人的姓名********\n"); scanf("%s",&namef); fp=fopen("num","r"); fscanf(fp,"%d",&n); struct qq q[n]; fclose(fp); fp=fopen("QQ","r"); for (i=0;i<n;i++) { fread(&q[i],sizeof(struct qq),1,fp); if (strcmp(q[i].name,namef)==0) kk=i; } fclose(fp); if (kk==-1) { printf("sorry, the name can't be found.\n"); printf("put any key continue.\n"); return 0; } else fp=fopen("QQ","w"); for (i=0;i<kk;i++) fwrite(&q[i],sizeof(struct qq),1,fp); for (i=kk+1;i<n;i++) fwrite(&q[i],sizeof(struct qq),1,fp); fclose(fp); n=n-1; fp=fopen("num","w"); fprintf(fp,"%d",n); fclose(fp); } |
|
|
| 60.223.16.* |
2楼 |
|
|
| 202.116.27.* |
3楼 鼓励一下了。呵呵! |
|
|
| 61.55.8.* |
4楼 |
|
|
| 218.19.141.* |
6楼 |
|
|
|
7楼 #include "stdio.h" #include "conio.h" struct address_list { char tel[20]; char name[10]; char address[30]; }addr[1]; main() { int kk=1;char choice; loop2 : init(); loop : scanf("%c",&choice); switch(choice) { case 'c': case 'C': newf();break; case 'n': case 'N': break; case 'l': case 'L': listf();getch();goto loop2; case 'f': case 'F': findf();getch();goto loop2; case 'd': case 'D': deletef();getch();goto loop2; case 'q': case 'Q': return 0; case 'a': case 'A': alterf();goto loop2; default: goto loop; } while(kk==1) { addf(); printf("enter 1 to continue add.\n"); scanf("%d",&kk); system("cls"); } goto loop2; } int init() { printf("\n*****************************************\n"); printf("******第一次用本程序请按c(create)********\n"); printf("**********增加记录请按n(new)*************\n"); printf("*********查看记录情况请按l(list)*********\n"); printf("******查询某个记录情况请按f(find)********\n"); printf("*********删除记录请按d(delete)***********\n"); printf("**********修改记录请按a(alter)***********\n"); printf("************退出请按q(quit)**************\n"); printf("*****************************************\n"); } int newf() { FILE *fp,*Fp; int n; Fp=fopen("QQ","w"); fclose(Fp); fp=fopen("num","w"); n=0; fprintf(fp,"%d",n); fclose(fp); } int addf() { FILE *fp1,*fp;int n; printf("*****************************************\n"); printf("*****请依次输入电话号码,姓名,地址.*******\n"); printf("*****************************************\n"); fp1=fopen("QQ","a"); scanf("%s%s%s",&addr[0].tel,&addr[0].name,&addr[0].address); fwrite(&addr[0],sizeof(struct address_list),1,fp1); fclose(fp1); fp=fopen("num","r"); fscanf(fp,"%d",&n); fclose(fp); fp=fopen("num","w"); n++; fprintf(fp,"%d",n); fclose(fp); } int listf() { FILE *fp;int n,i,k=0; fp=fopen("num","r"); fscanf(fp,"%d",&n); fclose(fp); fp=fopen("QQ","r"); for (i=0;i<n;i++) { fread(&addr[0],sizeof(struct address_list),1,fp); printf("电话:%s\n姓名:%s\n地址:%s\n\n\n",&addr[0].tel,&addr[0].name,&addr[0].address); k++; if (k%4==0) {printf("\nput any key continue\n"); getch();system("cls");k=0;} } fclose(fp); } int findf() { char namef[10];int n,i; FILE *fp; printf("\n*******请输入姓名********\n"); scanf("%s",&namef); fp=fopen("num","r"); fscanf(fp,"%d",&n); struct address_list q[n]; fclose(fp); fp=fopen("QQ","r"); for (i=0;i<n;i++) { fread(&q[i],sizeof(struct address_list),1,fp); if (strcmp(q[i].name,namef)==0) { printf("电话:%s\n姓名:%s\n地址:%s\n\n\n",&q[i].tel,&q[i].name,&q[i].address); fclose(fp); return 0; } } printf("sorry, the name can't be found.\n"); printf("put any key continue.\n"); fclose(fp); } int deletef() { char namef[10];int n,i,kk=-1; FILE *fp; printf("\n*******请输入要删除电话人的姓名********\n"); scanf("%s",&namef); fp=fopen("num","r"); fscanf(fp,"%d",&n); struct address_list q[n]; fclose(fp); fp=fopen("QQ","r"); for (i=0;i<n;i++) { fread(&q[i],sizeof(struct address_list),1,fp); if (strcmp(q[i].name,namef)==0) kk=i; } fclose(fp); if (kk==-1) { printf("sorry, the name can't be found.\n"); printf("put any key continue.\n"); return 0; } else fp=fopen("QQ","w"); for (i=0;i<kk;i++) fwrite(&q[i],sizeof(struct address_list),1,fp); for (i=kk+1;i<n;i++) fwrite(&q[i],sizeof(struct address_list),1,fp); fclose(fp); n=n-1; fp=fopen("num","w"); fprintf(fp,"%d",n); fclose(fp); } int alterf() { char namef[10];int n,i,kk=-1; FILE *fp; printf("\n*******请输入要修改人的姓名********\n"); scanf("%s",&namef); fp=fopen("num","r"); fscanf(fp,"%d",&n); struct address_list q[n]; fclose(fp); fp=fopen("QQ","r"); for (i=0;i<n;i++) { fread(&q[i],sizeof(struct address_list),1,fp); if (strcmp(q[i].name,namef)==0) { kk=i; printf("输入修改后的电话号码和地址.\n"); scanf("%s%s",&q[i].tel,&q[i].address); } } if (kk==-1) { printf("sorry, the name can't be found.\n"); printf("put any key continue.\n"); getch(); fclose(fp);return 0; } else fclose(fp); fp=fopen("QQ","w"); for (i=0;i<n;i++) fwrite(&q[i],sizeof(struct address_list),1,fp); fclose(fp); } |
|
|
|
| 61.181.232.* |
9楼 |
|
|
| 202.116.25.* |
10楼 |
|
|
| 222.49.91.* |
11楼 |
|
|
| 218.5.5.* |
12楼 |
|
|
| 202.116.20.* |
13楼 |
|
|
| 202.116.20.* |
15楼 |
|
|
| 218.87.41.* |
16楼 |
|
|
| 218.246.234.* |
17楼 #include <stdlib.h> #include <conio.h> #include <string.h> //#include <dos.h> #include <io.h> //名字最好用英文,如果不会英文就全部应汉语拼音,主要是可读性 struct USER { char Name[10]; char Age[3]; char QQ[12]; char Tel[15]; char Address[50]; }User; //测试字符串是否全是数字 bool TestType(char buf[]) { for(int i=0;i<sizeof(buf);i++) { if(buf[i]==0) break; if(buf[i]<'0' || buf[i]>'9') return false; } return true; } void DisplayMenu() //这里只是显示不用返回int类型 { printf("\n******************************\n"); printf("*********增加记录请按1**********\n"); printf("*******查看记录情况请按2*******\n"); printf("*****查询某个记录情况请按3*****\n"); printf("***********退出请按Esc*********\n"); printf("*******************************\n"); } void DisplayInfoMenu() { printf("\n*****************************\n"); printf("*******查看上一条记录按1*******\n"); printf("*******查看下一条记录按2*******\n"); printf("**********删除信息按3**********\n"); printf("**********退出请按Esc**********\n"); printf("*******************************\n"); } void DisplayInfo(char buf[]="") { FILE *fp; char Key; fp=fopen("User.txt","r+"); fread(&User,sizeof(USER),1,fp); if(stricmp(buf,"")) { while(stricmp(User.Name,buf)) { fread(&User,sizeof(USER),1,fp); if(feof(fp)) { printf("没有查到信息,按任意键继续..."); getch(); return; } } } do { system("cls"); DisplayInfoMenu(); printf("姓名:%s\n年龄:%s\nQQ号:%s\n电话:%s\n地址:%s\n",&User.Name,&User.Age,&User.QQ,&User.Tel,&User.Address); Key=getch(); switch(Key) { case '1': case '!': if(fseek(fp,0-sizeof(USER)*2,SEEK_CUR)==-1) fseek(fp,0,SEEK_SET); fread(&User,sizeof(USER),1,fp); break; case '2': case '@': fread(&User,sizeof(USER),1,fp); break; case '3': case '#': int buf=0; fpos_t pos; while(true) { if(fread(&User,sizeof(USER),1,fp)==0) //如果文件尾 { fgetpos(fp,&pos); chsize(fileno(fp), pos-sizeof(USER)); break; } fseek(fp,0-sizeof(USER)*2,SEEK_CUR); fwrite(&User,sizeof(USER),1,fp); fseek(fp,sizeof(USER),SEEK_CUR); } fread(&User,sizeof(USER),1,fp); break; } }while(Key!=0x1B); fclose(fp); } void AddUser() { FILE *fp; printf("请输入姓名:"); scanf("%s",&User.Name); printf("请输入年龄:"); do{scanf("%sL3",&User.Age); }while(!TestType(User.Age)&&printf("输入的年龄必须全是数字:")); printf("请输入QQ号:"); do{scanf("%s",&User.QQ); }while(!TestType(User.QQ)&&printf("输入的QQ号必须全是数字:")); printf("请输入电话:"); do{scanf("%s",&User.Tel); }while(!TestType(User.Tel)&&printf("输入的电话必须全是数字:")); printf("请输入地址:"); scanf("%s",&User.Address); fp=fopen("User.txt","a"); fwrite(&User,sizeof(USER),1,fp); fclose(fp); } void FindInfo() { char buf[10]; printf("请输入查找的姓名:"); scanf("%s",&buf); DisplayInfo(buf); } void main() { //在程序尽量不要用goto,我把你的循环改了 char Key; do { system("cls"); DisplayMenu(); printf("请选择功能.\n"); Key=getch(); //用函数的到按键比你那样明显 switch(Key) { case '1': //如果换成1、2、3、4来操作那会更方便点 case '!': AddUser(); break; case '2': case '@': DisplayInfo(); break; case '3': case '#': FindInfo(); break; case '4': case '$': break; } }while(Key!=0x1B); //0x1B是Esc键,也就是按Esc键退出 } 写的不错,我把程序优化了一下,是用vc写的不知道头文件tc里有没有。 |
|
|
| 220.176.24.* |
18楼 |
|
|
|
20楼 |
|
|
|
| 211.114.177.* |
23楼 |
|
|
| 211.114.177.* |
24楼 |
|
|
|
26楼 Compiling... Cpp1.cpp g:\c\cpp1.cpp(15) : error C2065: 'init' : undeclared identifier g:\c\cpp1.cpp(19) : error C2065: 'newf' : undeclared identifier g:\c\cpp1.cpp(21) : error C2065: 'listf' : undeclared identifier g:\c\cpp1.cpp(22) : error C2065: 'findf' : undeclared identifier g:\c\cpp1.cpp(23) : error C2065: 'deletef' : undeclared identifier g:\c\cpp1.cpp(25) : error C2065: 'alterf' : undeclared identifier g:\c\cpp1.cpp(30) : error C2065: 'addf' : undeclared identifier g:\c\cpp1.cpp(33) : error C2065: 'system' : undeclared identifier g:\c\cpp1.cpp(39) : error C2373: 'init' : redefinition; different type modifiers g:\c\cpp1.cpp(51) : error C2373: 'newf' : redefinition; different type modifiers g:\c\cpp1.cpp(61) : error C2373: 'addf' : redefinition; different type modifiers g:\c\cpp1.cpp(79) : error C2373: 'listf' : redefinition; different type modifiers g:\c\cpp1.cpp(96) : error C2373: 'findf' : redefinition; different type modifiers g:\c\cpp1.cpp(103) : error C2057: expected constant expression g:\c\cpp1.cpp(103) : error C2466: cannot allocate an array of constant size 0 g:\c\cpp1.cpp(103) : error C2133: 'q' : unknown size g:\c\cpp1.cpp(109) : error C2065: 'strcmp' : undeclared identifier g:\c\cpp1.cpp(121) : error C2373: 'deletef' : redefinition; different type modifiers g:\c\cpp1.cpp(129) : error C2057: expected constant expression g:\c\cpp1.cpp(129) : error C2466: cannot allocate an array of constant size 0 g:\c\cpp1.cpp(129) : error C2133: 'q' : unknown size g:\c\cpp1.cpp(158) : error C2373: 'alterf' : redefinition; different type modifiers g:\c\cpp1.cpp(165) : error C2057: expected constant expression g:\c\cpp1.cpp(165) : error C2466: cannot allocate an array of constant size 0 g:\c\cpp1.cpp(165) : error C2133: 'q' : unknown size Error executing cl.exe. Cpp1.obj - 25 error(s), 0 warning(s) 这是我运行后的结果显示. |
|
|
|
|
28楼 --------------------Configuration: qq - Win32 Debug-------------------- Compiling... qq.cpp g:\c\qq.cpp(33) : error C2065: 'printf' : undeclared identifier g:\c\qq.cpp(53) : error C2065: 'FILE' : undeclared identifier g:\c\qq.cpp(53) : error C2065: 'fp' : undeclared identifier g:\c\qq.cpp(53) : warning C4552: '*' : operator has no effect; expected operator with side-effect g:\c\qq.cpp(55) : error C2065: 'fopen' : undeclared identifier g:\c\qq.cpp(56) : error C2065: 'fread' : undeclared identifier g:\c\qq.cpp(62) : error C2065: 'feof' : undeclared identifier g:\c\qq.cpp(80) : error C2065: 'fseek' : undeclared identifier g:\c\qq.cpp(80) : error C2065: 'SEEK_CUR' : undeclared identifier g:\c\qq.cpp(81) : error C2065: 'SEEK_SET' : undeclared identifier g:\c\qq.cpp(91) : error C2065: 'fpos_t' : undeclared identifier g:\c\qq.cpp(91) : error C2146: syntax error : missing ';' before identifier 'pos' g:\c\qq.cpp(91) : error C2065: 'pos' : undeclared identifier g:\c\qq.cpp(96) : error C2065: 'fgetpos' : undeclared identifier g:\c\qq.cpp(97) : error C2065: 'fileno' : undeclared identifier g:\c\qq.cpp(101) : error C2065: 'fwrite' : undeclared identifier g:\c\qq.cpp(108) : error C2065: 'fclose' : undeclared identifier g:\c\qq.cpp(113) : warning C4552: '*' : operator has no effect; expected operator with side-effect g:\c\qq.cpp(115) : error C2065: 'scanf' : undeclared identifier Error executing cl.exe. qq.obj - 17 error(s), 2 warning(s) |
|
|
|
|
29楼 #include <stdlib.h> #include <conio.h> #include <string.h> //#include <dos.h> #include <io.h> 这几行你COPY了吗? 看来你是不折不扣的新手.一点C都没学过吧? |
|
|
|
