#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct paper
{
int opus;
char sort[30];
char book[20];
char writer[20];
char press[30];
int number;
float price;
}std[15];
int Diaoyon = 10;
void menu()
{
printf("-------------------------\n");
printf("| 簡易圖書管理系統 |\n");
printf("-------------------------\n");
printf("| 1:顯示全部 |\n");
printf("| 2:按書名查詢 |\n");
printf("| 3:按作者查詢 |\n");
printf("| 4:按作者排序 |\n");
printf("| 5:按書名排序 |\n");
printf("| 6:添加記錄 |\n");
printf("| 7:修改資訊 |\n");
printf("| 8:總價 |\n");
printf("| 9:借閱查詢 |\n");
printf("| 0:結束 |\n");
printf("-------------------------\n");
}
int xsqb()
{
int i;
struct paper std[15];
printf("\n編號 分類 書名 作者 出版社 數量 單價");
for (i = 0; i < Diaoyon; i++)
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
}
int asmcx()
{
char book[20] = "";
int ibook = 0, i;
int G;
Loop:
printf("請輸入書名:");
fflush(stdin);
scanf("%s", book);
for (i = 0; i < Diaoyon; i++)
{
if (!strcmp(book, std[i].book))
{
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
ibook = 1;
}
if (!ibook)
{
printf("\n未找到匹配圖書");
}
printf("\n輸入33繼續查找:");
fflush(stdin);
scanf("%c", G);
if (G == 33)
goto Loop;
}
}
int azzcx()
{
char writer[20] = "";
int abook = 0, i;
int M;
Loop:
printf("請輸入作者名:");
fflush(stdin);
scanf("%s", writer);
for (i = 0; i < Diaoyon; i++)
{
if (!strcmp(writer, std[i].writer))
{
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
abook = 1;
}
if (!abook)
{
printf("\n未找到匹配圖書");
}
printf("\n輸入00繼續查找:");
fflush(stdin);
scanf("%c", M);
if (M == 00)
goto Loop;
}
}
int azzpx()
{
}
int asmpx()
{
}
int tjjl()
{
int i, a;
float j;
char zxc[30];
Loon:
printf("\n請按格式:編號 分類 書名 作者 數量 單價,輸入");
fflush(stdin);
scanf("%d", &a);
if (a >= 1 || a <= Diaoyon)
{
printf("編號重復,請輸入1到%d之外的數字:", Diaoyon);
goto Loon;
}
else
std[a - 1].opus = a;
scanf("%s", zxc);
strcpy(std[a - 1].sort, zxc);
scanf("%s", zxc);
strcpy(std[a - 1].book, zxc);
scanf("%s", zxc);
strcpy(std[a - 1].writer, zxc);
scanf("%s", zxc);
strcpy(std[a - 1].press, zxc);
scanf("%d", &i);
std[a - 1].number = i;
scanf("%0.2f", &j);
std[a - 1].price = j;
}
int xgxx()
{
int i, n;
char wtr[20];
float j;
Loot:
printf("請輸入需修改圖書編號:");
scanf("%d", &n);
if (n<1 || n>Diaoyon)
{
printf("輸入錯誤,編號在1到%d之間", Diaoyon);
goto Loot;
}
printf("所需圖書為:%d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort[30], std[n - 1].book[20], std[n - 1].writer[20], std[n - 1].press[30], std[n - 1].number, std[n - 1].price);
printf("修改順序為:\n 分類 書名 作者 出版社 數量 單價");
scanf("%s", wtr);
strcpy(std[n - 1].sort, wtr);
scanf("%s", wtr);
strcpy(std[n - 1].book, wtr);
scanf("%s", wtr);
strcpy(std[n - 1].writer, wtr);
scanf("%s", wtr);
strcpy(std[n - 1].press, wtr);
scanf("%d", &i);
std[n - 1].number = i;
scanf("%0.2f", &j);
std[n - 1].price = j;
printf("\n修改后所得為:\n %d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort[30], std[n - 1].book[20], std[n - 1].writer[20], std[n - 1].press[30], std[n - 1].number, std[n - 1].price);
}
int zj()
{
}
int jycx()
{
}
void ReadFile()
{
FILE *fp;
int i = 0, j;
if ((fp = fopen("JK0638.txt", "r")) == NULL)
{
printf("Cannot open file\n");
return;
}
fscanf(fp, "%s %s %s %s %s %s %s", std[0].opus, std[0].sort, std[0].book, std[0].writer, std[0].press, std[0].number, std[0].price);
while (!feof(fp))
{
fscanf(fp, "%d %s %s %s %s %d %f", &std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], &std[i].number, &std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
i++;
}
Diaoyon = i;
fclose(fp);
}
void main()
{
int ind;
do
{
ReadFile();
menu();
printf("請輸入操作編號:");
scanf("%d", &ind);
switch (ind)
{
case 1:xsqb(); break;
case 2:asmcx(); break;
case 3:azzcx(); break;
case 4:azzpx(); break;
case 5:asmpx(); break;
case 6:tjjl(); break;
case 7:xgxx(); break;
case 8:zj(); break;
case 9:jycx(); break;
case 0:exit(17);
}
} while (17);}
編譯沒有錯誤。只是運行的時候會出現
在2.886秒后退出,回傳值3221225477
uj5u.com熱心網友回復:
JK0638.txt檔案存在么?
uj5u.com熱心網友回復:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct paper
{
int opus;
char sort[30];
char book[20];
char writer[20];
char press[30];
int number;
float price;
}std[15];
int Diaoyon = 10;
void menu()
{
printf("-------------------------\n");
printf("| 簡易圖書管理系統 |\n");
printf("-------------------------\n");
printf("| 1:顯示全部 |\n");
printf("| 2:按書名查詢 |\n");
printf("| 3:按作者查詢 |\n");
printf("| 4:按作者排序 |\n");
printf("| 5:按書名排序 |\n");
printf("| 6:添加記錄 |\n");
printf("| 7:修改資訊 |\n");
printf("| 8:總價 |\n");
printf("| 9:借閱查詢 |\n");
printf("| 0:結束 |\n");
printf("-------------------------\n");
}
int xsqb()
{
int i;
struct paper std[15];
printf("\n編號 分類 書名 作者 出版社 數量 單價");
for (i = 0; i < Diaoyon; i++)
//printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, std[i].number, std[i].price);
return 0; //定義的是int型別
}
int asmcx()
{
char book[20] = "";
int ibook = 0, i;
int G;
Loop:
printf("請輸入書名:");
//fflush(stdin); //此句跟編譯器有關,不一定有效
scanf("%s", book);
for (i = 0; i < Diaoyon; i++)
{
if (!strcmp(book, std[i].book))
{
//printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, std[i].number, std[i].price);
ibook = 1;
}
}
//下面的陳述句應該放到for回圈外,而不是回圈里
if (!ibook)
{
printf("\n未找到匹配圖書");
}
printf("\n輸入33繼續查找:");
//fflush(stdin);
//scanf("%c", G);
scanf("%d", &G);
if (G == 33)
goto Loop;
return 0;
}
int azzcx()
{
char writer[20] = "";
int abook = 0, i;
int M;
Loop:
printf("請輸入作者名:");
fflush(stdin);
scanf("%s", writer);
for (i = 0; i < Diaoyon; i++)
{
if (!strcmp(writer, std[i].writer))
{
//printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, std[i].number, std[i].price);
abook = 1;
}
}
//下面的陳述句放到回圈外
if (!abook)
{
printf("\n未找到匹配圖書");
}
printf("\n輸入00繼續查找:");
//fflush(stdin);
//scanf("%c", M);
scanf("%d", &M);
if (M == 0)
goto Loop;
}
int azzpx()
{
return 0;
}
int asmpx()
{
return 0;
}
int tjjl()
{
int i, a;
float j;
char zxc[30];
Loon:
printf("\n請按格式:編號 分類 書名 作者 數量 單價,輸入");
//fflush(stdin);
scanf("%d", &a);
if (a >= 1 || a <= Diaoyon)
{
printf("編號重復,請輸入1到%d之外的數字:", Diaoyon);
goto Loon;
}
else
std[a - 1].opus = a;
scanf("%s", zxc);
strcpy(std[a - 1].sort, zxc);
scanf("%s", zxc);
strcpy(std[a - 1].book, zxc);
scanf("%s", zxc);
strcpy(std[a - 1].writer, zxc);
scanf("%s", zxc);
strcpy(std[a - 1].press, zxc);
scanf("%d", &i);
std[a - 1].number = i;
scanf("%0.2f", &j);
std[a - 1].price = j;
return 0;
}
int xgxx()
{
int i, n;
char wtr[20];
float j;
Loot:
printf("請輸入需修改圖書編號:");
scanf("%d", &n);
if (n<1 || n>Diaoyon)
{
printf("輸入錯誤,編號在1到%d之間", Diaoyon);
goto Loot;
}
//printf("所需圖書為:%d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort[30], std[n - 1].book[20], std[n - 1].writer[20], std[n - 1].press[30], std[n - 1].number, std[n - 1].price);
printf("所需圖書為:%d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort, std[n - 1].book, std[n - 1].writer, std[n - 1].press, std[n - 1].number, std[n - 1].price);
printf("修改順序為:\n 分類 書名 作者 出版社 數量 單價");
scanf("%s", wtr);
strcpy(std[n - 1].sort, wtr);
scanf("%s", wtr);
strcpy(std[n - 1].book, wtr);
scanf("%s", wtr);
strcpy(std[n - 1].writer, wtr);
scanf("%s", wtr);
strcpy(std[n - 1].press, wtr);
scanf("%d", &i);
std[n - 1].number = i;
scanf("%0.2f", &j);
std[n - 1].price = j;
//printf("\n修改后所得為:\n %d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort[30], std[n - 1].book[20], std[n - 1].writer[20], std[n - 1].press[30], std[n - 1].number, std[n - 1].price);
printf("\n修改后所得為:\n %d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort, std[n - 1].book, std[n - 1].writer, std[n - 1].press, std[n - 1].number, std[n - 1].price);
}
int zj()
{
}
int jycx()
{
}
void ReadFile()
{
FILE *fp;
int i = 0, j;
if ((fp = fopen("JK0638.txt", "r")) == NULL)
{
printf("Cannot open file\n");
return;
}
//fscanf(fp, "%s %s %s %s %s %s %s", std[0].opus, std[0].sort, std[0].book, std[0].writer, std[0].press, std[0].number, std[0].price);
fscanf(fp, "%d %s %s %s %s %d %f", &std[0].opus, std[0].sort, std[0].book, std[0].writer, std[0].press, &std[0].number, &std[0].price);
while (!feof(fp))
{
//fscanf(fp, "%d %s %s %s %s %d %f", &std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], &std[i].number, &std[i].price);
fscanf(fp, "%d %s %s %s %s %d %f", &std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, &std[i].number, &std[i].price);
//printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, std[i].number, std[i].price);
i++;
}
Diaoyon = i;
fclose(fp);
}
void main()
{
int ind;
do
{
ReadFile();
menu();
printf("請輸入操作編號:");
scanf("%d", &ind);
switch (ind)
{
case 1:xsqb(); break;
case 2:asmcx(); break;
case 3:azzcx(); break;
case 4:azzpx(); break;
case 5:asmpx(); break;
case 6:tjjl(); break;
case 7:xgxx(); break;
case 8:zj(); break;
case 9:jycx(); break;
case 0:exit(17);
}
} while (17); //這兒為什么用17,用1不一樣嗎?
}
供參考~
代碼問題比較多,但是歸納起來也就幾個,多出是相同的錯誤。建議樓主對比代碼找一下自己的問題~
uj5u.com熱心網友回復:
參考 2 樓 自信男孩的回復: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct paper
{
int opus;
char sort[30];
char book[20];
char writer[20];
char press[30];
int number;
float price;
}std[15];
int Diaoyon = 10;
void menu()
{
printf("-------------------------\n");
printf("| 簡易圖書管理系統 |\n");
printf("-------------------------\n");
printf("| 1:顯示全部 |\n");
printf("| 2:按書名查詢 |\n");
printf("| 3:按作者查詢 |\n");
printf("| 4:按作者排序 |\n");
printf("| 5:按書名排序 |\n");
printf("| 6:添加記錄 |\n");
printf("| 7:修改資訊 |\n");
printf("| 8:總價 |\n");
printf("| 9:借閱查詢 |\n");
printf("| 0:結束 |\n");
printf("-------------------------\n");
}
int xsqb()
{
int i;
struct paper std[15];
printf("\n編號 分類 書名 作者 出版社 數量 單價");
for (i = 0; i < Diaoyon; i++)
//printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, std[i].number, std[i].price);
return 0; //定義的是int型別
}
int asmcx()
{
char book[20] = "";
int ibook = 0, i;
int G;
Loop:
printf("請輸入書名:");
//fflush(stdin); //此句跟編譯器有關,不一定有效
scanf("%s", book);
for (i = 0; i < Diaoyon; i++)
{
if (!strcmp(book, std[i].book))
{
//printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, std[i].number, std[i].price);
ibook = 1;
}
}
//下面的陳述句應該放到for回圈外,而不是回圈里
if (!ibook)
{
printf("\n未找到匹配圖書");
}
printf("\n輸入33繼續查找:");
//fflush(stdin);
//scanf("%c", G);
scanf("%d", &G);
if (G == 33)
goto Loop;
return 0;
}
int azzcx()
{
char writer[20] = "";
int abook = 0, i;
int M;
Loop:
printf("請輸入作者名:");
fflush(stdin);
scanf("%s", writer);
for (i = 0; i < Diaoyon; i++)
{
if (!strcmp(writer, std[i].writer))
{
//printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, std[i].number, std[i].price);
abook = 1;
}
}
//下面的陳述句放到回圈外
if (!abook)
{
printf("\n未找到匹配圖書");
}
printf("\n輸入00繼續查找:");
//fflush(stdin);
//scanf("%c", M);
scanf("%d", &M);
if (M == 0)
goto Loop;
}
int azzpx()
{
return 0;
}
int asmpx()
{
return 0;
}
int tjjl()
{
int i, a;
float j;
char zxc[30];
Loon:
printf("\n請按格式:編號 分類 書名 作者 數量 單價,輸入");
//fflush(stdin);
scanf("%d", &a);
if (a >= 1 || a <= Diaoyon)
{
printf("編號重復,請輸入1到%d之外的數字:", Diaoyon);
goto Loon;
}
else
std[a - 1].opus = a;
scanf("%s", zxc);
strcpy(std[a - 1].sort, zxc);
scanf("%s", zxc);
strcpy(std[a - 1].book, zxc);
scanf("%s", zxc);
strcpy(std[a - 1].writer, zxc);
scanf("%s", zxc);
strcpy(std[a - 1].press, zxc);
scanf("%d", &i);
std[a - 1].number = i;
scanf("%0.2f", &j);
std[a - 1].price = j;
return 0;
}
int xgxx()
{
int i, n;
char wtr[20];
float j;
Loot:
printf("請輸入需修改圖書編號:");
scanf("%d", &n);
if (n<1 || n>Diaoyon)
{
printf("輸入錯誤,編號在1到%d之間", Diaoyon);
goto Loot;
}
//printf("所需圖書為:%d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort[30], std[n - 1].book[20], std[n - 1].writer[20], std[n - 1].press[30], std[n - 1].number, std[n - 1].price);
printf("所需圖書為:%d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort, std[n - 1].book, std[n - 1].writer, std[n - 1].press, std[n - 1].number, std[n - 1].price);
printf("修改順序為:\n 分類 書名 作者 出版社 數量 單價");
scanf("%s", wtr);
strcpy(std[n - 1].sort, wtr);
scanf("%s", wtr);
strcpy(std[n - 1].book, wtr);
scanf("%s", wtr);
strcpy(std[n - 1].writer, wtr);
scanf("%s", wtr);
strcpy(std[n - 1].press, wtr);
scanf("%d", &i);
std[n - 1].number = i;
scanf("%0.2f", &j);
std[n - 1].price = j;
//printf("\n修改后所得為:\n %d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort[30], std[n - 1].book[20], std[n - 1].writer[20], std[n - 1].press[30], std[n - 1].number, std[n - 1].price);
printf("\n修改后所得為:\n %d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort, std[n - 1].book, std[n - 1].writer, std[n - 1].press, std[n - 1].number, std[n - 1].price);
}
int zj()
{
}
int jycx()
{
}
void ReadFile()
{
FILE *fp;
int i = 0, j;
if ((fp = fopen("JK0638.txt", "r")) == NULL)
{
printf("Cannot open file\n");
return;
}
//fscanf(fp, "%s %s %s %s %s %s %s", std[0].opus, std[0].sort, std[0].book, std[0].writer, std[0].press, std[0].number, std[0].price);
fscanf(fp, "%d %s %s %s %s %d %f", &std[0].opus, std[0].sort, std[0].book, std[0].writer, std[0].press, &std[0].number, &std[0].price);
while (!feof(fp))
{
//fscanf(fp, "%d %s %s %s %s %d %f", &std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], &std[i].number, &std[i].price);
fscanf(fp, "%d %s %s %s %s %d %f", &std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, &std[i].number, &std[i].price);
//printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, std[i].number, std[i].price);
i++;
}
Diaoyon = i;
fclose(fp);
}
void main()
{
int ind;
do
{
ReadFile();
menu();
printf("請輸入操作編號:");
scanf("%d", &ind);
switch (ind)
{
case 1:xsqb(); break;
case 2:asmcx(); break;
case 3:azzcx(); break;
case 4:azzpx(); break;
case 5:asmpx(); break;
case 6:tjjl(); break;
case 7:xgxx(); break;
case 8:zj(); break;
case 9:jycx(); break;
case 0:exit(17);
}
} while (17); //這兒為什么用17,用1不一樣嗎?
}
供參考~
代碼問題比較多,但是歸納起來也就幾個,多出是相同的錯誤。建議樓主對比代碼找一下自己的問題~
可以了,十分感謝
uj5u.com熱心網友回復:
參考 3 樓 qq_48935908 的回復: Quote: 參考 2 樓 自信男孩的回復: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct paper
{
int opus;
char sort[30];
char book[20];
char writer[20];
char press[30];
int number;
float price;
}std[15];
int Diaoyon = 10;
void menu()
{
printf("-------------------------\n");
printf("| 簡易圖書管理系統 |\n");
printf("-------------------------\n");
printf("| 1:顯示全部 |\n");
printf("| 2:按書名查詢 |\n");
printf("| 3:按作者查詢 |\n");
printf("| 4:按作者排序 |\n");
printf("| 5:按書名排序 |\n");
printf("| 6:添加記錄 |\n");
printf("| 7:修改資訊 |\n");
printf("| 8:總價 |\n");
printf("| 9:借閱查詢 |\n");
printf("| 0:結束 |\n");
printf("-------------------------\n");
}
int xsqb()
{
int i;
struct paper std[15];
printf("\n編號 分類 書名 作者 出版社 數量 單價");
for (i = 0; i < Diaoyon; i++)
//printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, std[i].number, std[i].price);
return 0; //定義的是int型別
}
int asmcx()
{
char book[20] = "";
int ibook = 0, i;
int G;
Loop:
printf("請輸入書名:");
//fflush(stdin); //此句跟編譯器有關,不一定有效
scanf("%s", book);
for (i = 0; i < Diaoyon; i++)
{
if (!strcmp(book, std[i].book))
{
//printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, std[i].number, std[i].price);
ibook = 1;
}
}
//下面的陳述句應該放到for回圈外,而不是回圈里
if (!ibook)
{
printf("\n未找到匹配圖書");
}
printf("\n輸入33繼續查找:");
//fflush(stdin);
//scanf("%c", G);
scanf("%d", &G);
if (G == 33)
goto Loop;
return 0;
}
int azzcx()
{
char writer[20] = "";
int abook = 0, i;
int M;
Loop:
printf("請輸入作者名:");
fflush(stdin);
scanf("%s", writer);
for (i = 0; i < Diaoyon; i++)
{
if (!strcmp(writer, std[i].writer))
{
//printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, std[i].number, std[i].price);
abook = 1;
}
}
//下面的陳述句放到回圈外
if (!abook)
{
printf("\n未找到匹配圖書");
}
printf("\n輸入00繼續查找:");
//fflush(stdin);
//scanf("%c", M);
scanf("%d", &M);
if (M == 0)
goto Loop;
}
int azzpx()
{
return 0;
}
int asmpx()
{
return 0;
}
int tjjl()
{
int i, a;
float j;
char zxc[30];
Loon:
printf("\n請按格式:編號 分類 書名 作者 數量 單價,輸入");
//fflush(stdin);
scanf("%d", &a);
if (a >= 1 || a <= Diaoyon)
{
printf("編號重復,請輸入1到%d之外的數字:", Diaoyon);
goto Loon;
}
else
std[a - 1].opus = a;
scanf("%s", zxc);
strcpy(std[a - 1].sort, zxc);
scanf("%s", zxc);
strcpy(std[a - 1].book, zxc);
scanf("%s", zxc);
strcpy(std[a - 1].writer, zxc);
scanf("%s", zxc);
strcpy(std[a - 1].press, zxc);
scanf("%d", &i);
std[a - 1].number = i;
scanf("%0.2f", &j);
std[a - 1].price = j;
return 0;
}
int xgxx()
{
int i, n;
char wtr[20];
float j;
Loot:
printf("請輸入需修改圖書編號:");
scanf("%d", &n);
if (n<1 || n>Diaoyon)
{
printf("輸入錯誤,編號在1到%d之間", Diaoyon);
goto Loot;
}
//printf("所需圖書為:%d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort[30], std[n - 1].book[20], std[n - 1].writer[20], std[n - 1].press[30], std[n - 1].number, std[n - 1].price);
printf("所需圖書為:%d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort, std[n - 1].book, std[n - 1].writer, std[n - 1].press, std[n - 1].number, std[n - 1].price);
printf("修改順序為:\n 分類 書名 作者 出版社 數量 單價");
scanf("%s", wtr);
strcpy(std[n - 1].sort, wtr);
scanf("%s", wtr);
strcpy(std[n - 1].book, wtr);
scanf("%s", wtr);
strcpy(std[n - 1].writer, wtr);
scanf("%s", wtr);
strcpy(std[n - 1].press, wtr);
scanf("%d", &i);
std[n - 1].number = i;
scanf("%0.2f", &j);
std[n - 1].price = j;
//printf("\n修改后所得為:\n %d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort[30], std[n - 1].book[20], std[n - 1].writer[20], std[n - 1].press[30], std[n - 1].number, std[n - 1].price);
printf("\n修改后所得為:\n %d %s %s %s %s %d %0.2f", std[n - 1].opus, std[n - 1].sort, std[n - 1].book, std[n - 1].writer, std[n - 1].press, std[n - 1].number, std[n - 1].price);
}
int zj()
{
}
int jycx()
{
}
void ReadFile()
{
FILE *fp;
int i = 0, j;
if ((fp = fopen("JK0638.txt", "r")) == NULL)
{
printf("Cannot open file\n");
return;
}
//fscanf(fp, "%s %s %s %s %s %s %s", std[0].opus, std[0].sort, std[0].book, std[0].writer, std[0].press, std[0].number, std[0].price);
fscanf(fp, "%d %s %s %s %s %d %f", &std[0].opus, std[0].sort, std[0].book, std[0].writer, std[0].press, &std[0].number, &std[0].price);
while (!feof(fp))
{
//fscanf(fp, "%d %s %s %s %s %d %f", &std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], &std[i].number, &std[i].price);
fscanf(fp, "%d %s %s %s %s %d %f", &std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, &std[i].number, &std[i].price);
//printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort[30], std[i].book[20], std[i].writer[20], std[i].press[30], std[i].number, std[i].price);
printf("%d %s %s %s %s %d %0.2f", std[i].opus, std[i].sort, std[i].book, std[i].writer, std[i].press, std[i].number, std[i].price);
i++;
}
Diaoyon = i;
fclose(fp);
}
void main()
{
int ind;
do
{
ReadFile();
menu();
printf("請輸入操作編號:");
scanf("%d", &ind);
switch (ind)
{
case 1:xsqb(); break;
case 2:asmcx(); break;
case 3:azzcx(); break;
case 4:azzpx(); break;
case 5:asmpx(); break;
case 6:tjjl(); break;
case 7:xgxx(); break;
case 8:zj(); break;
case 9:jycx(); break;
case 0:exit(17);
}
} while (17); //這兒為什么用17,用1不一樣嗎?
}
供參考~
代碼問題比較多,但是歸納起來也就幾個,多出是相同的錯誤。建議樓主對比代碼找一下自己的問題~
可以了,十分感謝
最重要的是找出自己錯誤的原因,然后總結學到的東西~
uj5u.com熱心網友回復:
參考 1 樓 棉猴的回復: JK0638.txt檔案存在么?
存在,只是一直cannot open file
uj5u.com熱心網友回復:
參考 1 樓 棉猴的回復: JK0638.txt檔案存在么?
存在,只是一直cannot open file
uj5u.com熱心網友回復:
干脆用JK0638.txt的絕對路徑吧
uj5u.com熱心網友回復:
就算用絕對路徑也打不開。
uj5u.com熱心網友回復:
參考 7 樓 棉猴的回復: 干脆用JK0638.txt的絕對路徑吧
就算用絕對路徑也打不開。
uj5u.com熱心網友回復:
看一下打開檔案函式的回傳值,確定打不開檔案的原因是什么?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/34196.html
標籤:C語言
上一篇:編了一個學生管理系統,怎么批量洗掉學生資訊?
下一篇:求問前輩