求助C:unreferenced local variable
Cpp971.cpp(257) : warning C4101: 'Newname' : unreferenced local variableCpp971.cpp(327) : error C2065: 'N' : undeclared identifier
Cpp971.cpp(327) : error C2057: expected constant expression
好几个错误,代码如下
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define NSTUD 2500
void createText();
void findByxh();
void modiByxh();
void deleteByxh();
void tj();
void sortByye();
void mcByye();
void displayTextfile();
struct cardone
{char xh[30];char xm[30];char sj[100];char lx[30];double ye;double jye;
char dd[30];}jgt1,jgt2;
struct cardoneall
{char xh[20],xm[20],sj[20],dd[20],lx[20];double jye,ye;int id,mc;};
void main()
{
int choice=1;
while(choice>0)
{
printf("=======================================================\n");
printf("\t1.======================创建文本文件录入信息\n");
printf("\t2.======================按学号查询\n");
printf("\t3.======================按学号修改\n");
printf("\t4.======================按学号删除\n");
printf("\t5.======================按余额统计\n");
printf("\t6.======================按余额排序\n");
printf("\t7.======================按余额给名次\n");
printf("\t8.======================显示任意文件内容\n");
printf("\t0.======================结束\n");
printf("=======================================================\n");
printf("\t 请选择一个功能(0---6):\n");
scanf("%d",&choice);
fflush(stdin);
switch(choice)
{
case 1:
createText();
break;
case 2:
findByxh();
break;
case 3:
modiByxh();
break;
case 4:
deleteByxh();
break;
case 5:
tj();
break;
case 6:
sortByye();
break;
case 7:
mcByye();
break;
case 8:
displayTextfile();
break;
default:
printf("输入有误请检索后重新输入:\n");
break;
}
}
system("pause");
}
//==================create==================
void createtext()
{
char filename[20];
FILE *fp=NULL;
int j=0;
printf("请输入数据存放文件夹名称:");
gets(filename);
fflush(stdin);
fp=fopen(filename,"w");
if(fp==NULL){
printf("打开文件%s错误",filename);
getch();
exit(0);
}
printf("请输入学号:");
gets(jgt1.xh);
fflush(stdin);
printf("请输入姓名:");
gets(jgt1.xm);
fflush(stdin);
printf("请输入时间:");
gets(jgt1.sj);
fflush(stdin);
printf("请输入地点:");
gets(jgt1.dd);
fflush(stdin);
printf("请输入交易类型:");
gets(jgt1.lx);
fflush(stdin);
printf("请输入余额:");
scanf("%lf",&jgt1.ye);
fflush(stdin);
while(strcmp(jgt1.xh,"-1")!=0)
{
if(j>0){fprintf(fp,"\n");}
fprintf(fp,"%s %s %s %.2lf %s %s",
jgt1.xh,jgt1.xm,jgt1.sj,jgt1.ye,jgt1.dd,jgt1.lx);
printf("请输入学号:");
gets(jgt1.xh);
fflush(stdin);
printf("请输入姓名:");
gets(jgt1.xm);
fflush(stdin);
printf("请输入时间:");
gets(jgt1.sj);
fflush(stdin);
printf("请输入地点:");
gets(jgt1.dd);
fflush(stdin);
printf("请输入交易类型:");
gets(jgt1.lx);
fflush(stdin);
printf("请输入余额:");
scanf("%lf",&jgt1.ye);
fflush(stdin);
j++;
}
printf("请查看%s中的内容",filename);
fclose(fp);
getch();
}
//==================find==================
void findbyxh()
{
char keyxh[20],filename[20];
int j=0,n=1;
FILE *fp=NULL;
printf("请输入文件名:");
gets(filename);
fflush(stdin);
fp=fopen(filename,"r");
if(fp==NULL){
printf("打开文件%s错误!",filename);getch();exit(0);
}
else{
printf("请输入要查找的学号:");gets(keyxh);fflush(stdin);
}
while(!feof(fp))
{
fscanf(fp,"%s %s %s %lf %lf %s %s",
jgt1.xh,jgt1.xm,jgt1.sj,&jgt1.jye,&jgt1.ye,jgt1.dd,jgt1.lx);
if(strcmp(jgt1.xh,keyxh)==0){
j=1;printf("已找到学号为%s的同学,序号为%d!\n",keyxh,n);break;
}
n++;
}
if (j==0){printf("没找到学号为%s的同学!",keyxh);}
else{printf("已找到,该同学数据信息为:\n%s %s %s %.2lf %.2lf %s %s",jgt1.xh,
jgt1.xm,jgt1.sj,jgt1.jye,jgt1.ye,jgt1.dd,jgt1.lx);}
fclose(fp);getch();
}
//==================modi==================
void modifybyxh()
{
char keyxh[20],filename[20],newfile[20],newxm[20];
int j=0,n=0;
FILE *fp=NULL,*fp2=NULL;
printf("请输入文件名:");
gets(filename);
fflush(stdin);
fp=fopen(filename,"r");
if(fp==NULL){
printf("打开文件%s错误!",filename);getch();exit(0);
}
else {
printf("请创建新文件:");gets(newfile);fflush(stdin);
}
fp2=fopen(newfile,"w");
printf("请输入要查找的学号:");
gets(keyxh);
fflush(stdin);
printf("请输入新的姓名:");
gets(newxm);
fflush(stdin);
while(!feof(fp))
{
if(n>0){fprintf(fp2,"\n");}
fscanf(fp,"%s %s %s %lf %lf %s %s",
jgt1.xh,jgt1.xm,jgt1.sj,&jgt1.jye,&jgt1.ye,jgt1.dd,jgt1.lx);
if(strcmp(jgt1.xh,keyxh)==0){j=1;jgt2=jgt1;strcpy(jgt2.xm,newxm);
fprintf(fp2,"%s %s %s %.2lf %.2lf %s %s",jgt2.xh,
jgt2.xm,jgt2.sj,jgt2.jye,jgt2.ye,jgt2.dd,jgt2.lx);}
else {
fprintf(fp2,"%s %s %s %.2lf %.2lf %s %s",jgt1.xh,
jgt1.xm,jgt1.sj,jgt1.jye,jgt1.ye,jgt1.dd,jgt1.lx);
}
n++;
}
fclose(fp);
if (j==0){
printf("没找到学号为%s的同学!",keyxh);
}
else{
printf("被修改后的的同学数据信息为:\n%s %s %s %.2lf %.2lf %s %s",jgt2.xh,
jgt2.xm,jgt2.sj,jgt2.jye,jgt2.ye,jgt2.dd,jgt2.lx);
}
fclose(fp2);getch();
}
//==================delete==================
void deletebyxh()
{
char keyxh[20],filename[20],newfile[20];
int j=0,n=0;
FILE *fp=NULL,*fp2=NULL;
printf("请输入文件名:");
gets(filename);
fflush(stdin);
fp=fopen(filename,"r");
if(fp==NULL)
{
printf("打开文件%s错误!",filename);getch();exit(0);
}
else {
printf("请创建新文件:");gets(newfile);fflush(stdin);
}
fp2=fopen(newfile,"w");
printf("请输入要查找的学号:");gets(keyxh);fflush(stdin);
while(!feof(fp))
{
if(n>0){fprintf(fp2,"\n");}
fscanf(fp,"%s %s %s %lf %lf %s %s",
jgt1.xh,jgt1.xm,jgt1.sj,&jgt1.jye,&jgt1.ye,jgt1.dd,jgt1.lx);
if(strcmp(jgt1.xh,keyxh)==0){j=1;jgt2=jgt1;}
else{fprintf(fp2,"%s %s %s %.2lf %.2lf %s %s",jgt1.xh,
jgt1.xm,jgt1.sj,jgt1.jye,jgt1.ye,jgt1.dd,jgt1.lx);}
n++;
}
fclose(fp);
if (j==0){
printf("没找到学号为%s的同学!",keyxh);
}
else{
printf("被删除的同学数据信息为:\n%s %s %s %.2lf %.2lf %s %s",jgt2.xh,
jgt2.xm,jgt2.sj,jgt2.jye,jgt2.ye,jgt2.dd,jgt2.lx);
}
fclose(fp2);getch();
}
//==================tongji==================
void tj()
{
int ye[9]={0,0,0,0,0,0,0,0,0};
char Newname[20];
char *op=NULL;
FILE *fp1=NULL;
char fileName[30];
int i=0;
printf("请输入统计后数据信息存放文件夹名称:\n");
gets(fileName);
fflush(stdin);
op=fileName;
fp1=fopen(op,"w");
FILE *fp=fopen("D:\\summer2015\\struct1.txt","r");
while(!feof(fp))
{
fscanf(fp,"%s %s %s %lf %lf %s %s",jgt1.xh,jgt1.xm,jgt1.sj,&jgt1.jye,&jgt1.ye,jgt1.dd,jgt1.lx);
i++;
if(jgt1.ye >90){ ye[0]++;}
else if(jgt1.ye>80 ){ye[1]++;}
else if(jgt1.ye>70 ){ye[2]++;}
else if(jgt1.ye>60 ){ye[3]++;}
else if(jgt1.ye>50 ){ye[4]++;}
else if(jgt1.ye>40 ){ye[5]++;}
else if(jgt1.ye>30 ){ye[6]++;}
else if(jgt1.ye>20 ){ye[7]++;}
else ye[8]++;
}
fclose(fp);
printf("\n已完成操作请查看%s文件内的内容!\n",fileName);
fprintf(fp1,"校园一卡通同学卡内余额统计信息如下:\n");
fprintf(fp1,"本次一共统计%d名同学\n",i);
fprintf(fp1,"卡内余额在0-20元的同学人数为:%d\n",ye[8]);
fprintf(fp1,"卡内余额在20-30元的同学人数为:%d\n",ye[7]);
fprintf(fp1,"卡内余额在30-40元的同学人数为:%d\n",ye[6]);
fprintf(fp1,"卡内余额在40-50元的同学人数为:%d\n",ye[5]);
fprintf(fp1,"卡内余额在50-60元的同学人数为:%d\n",ye[4]);
fprintf(fp1,"卡内余额在60-70元的同学人数为:%d\n",ye[3]);
fprintf(fp1,"卡内余额在70-80元的同学人数为:%d\n",ye[2]);
fprintf(fp1,"卡内余额在80-90元的同学人数为:%d\n",ye[1]);
fprintf(fp1,"卡内余额大于90元的同学人数为:%d\n",ye[0]);
fprintf(fp1,"!谢谢使用!\n");
fclose(fp1);
}
//==================display==================
void displayTextfile()
{
char c,fileName[120];
FILE *fp=NULL;
printf("待查看的文件名:\n");
gets(fileName);
fflush(stdin);
fp=fopen(fileName,"r");
if (fp==NULL)
{
printf("文件%s打开出错",fileName);
getch();
exit(0);
}
while(!feof(fp))
{
c=fgetc(fp);
fputc(c,stdout);
}
fclose(fp);
}
//==================sortByye==================
void sortbyjye()
{
char filename[20],newfile[20];
int j=0,n=0,i=0;
FILE *fp=NULL,*fp2=NULL;
struct cardoneall jgt1[N],jgt2;
printf("请输入文件名:");
gets(filename);
fflush(stdin);
fp=fopen(filename,"r");
if(fp==NULL){
printf("打开文件%s错误!",filename);getch();exit(0);
}
else {
printf("请创建新文件:");gets(newfile);fflush(stdin);
}
fp2=fopen(newfile,"w");
while(!feof(fp))
{
fscanf(fp,"%s %s %s %lf %lf %s %s",
jgt1[i].xh,jgt1[i].xm,jgt1[i].sj,&jgt1[i].jye,&jgt1[i].ye,jgt1[i].dd,jgt1[i].lx);
i++;
}
fclose(fp);n=i;
if (n>N) {printf("实际%d>容量%d",n,N);getch();}
for (i=0;i<n-1;i++)
{
for (j=0;j<n-1-i;j++)
{
if (jgt1[j].jye>jgt1[j+1].jye)
{
jgt2=jgt1[j];jgt1[j]=jgt1[j+1];jgt1[j+1]=jgt2;
}
}
}
for (i=0;i<n;i++)
{
if(i>0){fprintf(fp2,"\n");}
fprintf(fp2,"%s %s %s %.2lf %.2lf %s %s",
jgt1[i].xh,jgt1[i].xm,jgt1[i].sj,jgt1[i].jye,jgt1[i].ye,jgt1[i].dd,jgt1[i].lx);
}
printf("请查看文件:%s!",newfile);fclose(fp2);getch();
}
//==================mcByye==================
void mcbyye()
{
char filename[20],newfile[20],newfile2[20];
int j=0,n=0,i=0,k;
FILE *fp=NULL,*fp2=NULL,*fp3=NULL;
struct cardoneall jgt1[N],jgt2;
printf("请输入文件名:");gets(filename);fflush(stdin);
fp=fopen(filename,"r");
if(fp==NULL){
printf("打开文件%s错误!",filename);
getch();
exit(0);
}
else{
printf("请创建文件1:");
gets(newfile);
fflush(stdin);
printf("请创建文件2:");
gets(newfile2);
fflush(stdin);
}
fp2=fopen(newfile,"w");
fp3=fopen(newfile2,"w");
while(!feof(fp))
{
fscanf(fp,"%s %s %s %lf %lf %s %s",
jgt1[i].xh,jgt1[i].xm,jgt1[i].sj,&jgt1[i].jye,&jgt1[i].ye,jgt1[i].dd,jgt1[i].lx);
jgt1[i].id=i;i++;
}
fclose(fp);n=i;
if (n>N) {printf("实际%d>容量%d",n,N);getch();}
for (i=0;i<n-1;i++)
{k=i;
for (j=i+1;j<n;j++)
{
if (jgt1[k].jye>jgt1[j].jye){k=j;}
}
if(k!=i){jgt2=jgt1[k];jgt1[k]=jgt1[i];jgt1[i]=jgt2;}
jgt1[i].mc=i+1;
}
jgt1[i].mc=i+1;
for (i=0;i<n;i++)
{
if(i>0){fprintf(fp2,"\n");}
fprintf(fp2,"%d %s %s %s %.2lf %.2lf %s %s %d",
jgt1[i].id,jgt1[i].xh,jgt1[i].xm,jgt1[i].sj,jgt1[i].jye,jgt1[i].ye,jgt1[i].dd,jgt1[i].lx,jgt1[i].mc);
}
printf("请查看文件:%s!",newfile);fclose(fp2);
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if (jgt1[j].id>jgt1[j+1].id) {jgt2=jgt1[j];jgt1[j]=jgt1[j+1];jgt1[j+1]=jgt2;}
}
}
for (i=0;i<n;i++)
{
if(i>0){fprintf(fp3,"\n");}
fprintf(fp3,"%d %s %s %s %.2lf %.2lf %s %s %d",
jgt1[i].id,jgt1[i].xh,jgt1[i].xm,jgt1[i].sj,jgt1[i].jye,jgt1[i].ye,jgt1[i].dd,jgt1[i].lx,jgt1[i].mc);
}
printf(" 请查看文件%s!",newfile2);fclose(fp3);getch();
}