本文目錄一覽:
哪位會C語言啊 看看這題啦
#include stdio.h
int sum(int n){
int sum = 0;
for(int i = 1; i n+ 1; i++ )
{
sum += i;
}
return sum;
}
int main(){
int a, b;
scanf(“%d”, a);
b = sum(a);
printf(“b = %d\n”, b);
return 0;
}
推薦一本書《linux 程序設計》,裡面對c語言講的通俗易懂
哪位會C語言啊?求高手幫我看看哪裡錯了,謝謝!
幫你改完。。。。。。。
int a[11]; // 數組大小改為11
int i,j,t,h,k;
printf(“input 10 number:\n”);
for(i=0;i10;i++)
scanf(“%d”,a[i]);
printf(“\n”);
for(j=0;j9;j++)
for(i=0;i9-j;i++)
if(a[i]a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
printf(“the sorted numbers:\n”);
for(i=0;i10;i++)
printf(“%d “,a[i]);
printf(“\n”);
//輸入一個數放在相應的位置
printf(“input 1 numbers:\n”);
scanf(“%d”,t);
if(ta[9])
a[10]=t;
else
{
for(i=0;i10;i++)
{
if(ta[i])
{
h=i;
for(k=9;k=h;k–) // 這部分內容提到這裡
a[k+1]=a[k];
a[h]=t;
break;
}
}
}
printf(“output 11 sorted numbers:\n”);
for(i=0;i11;i++)
printf(“%d “,a[i]);
哪位好心網友會c語言啊, 跪求解答! 1、輸入圓的半徑值,計算圓的周長和面
3.
#include stdio.h
int main()
{
int i,s=0;
for(i=1;i=99;i+=2)
s+=i;
printf(“1+3+5+…+99=%d\n”,s);
return 0;
}
誰會c語言啊?
#include “stdio.h”
#include “stdlib.h”
#include “string.h”
#include “conio.h”
struct time /*出版時間結構體*/
{
int year;
int month;
int day;
};
struct data /*圖書數據結構體*/
{
int num;
char bname[20];
char wname[15];
char clanum[15];
char pubcom[10];
struct time pubtime;
float price;
}books[20],book;
void face() /*程序主界面函數*/
{
system(“cls”);
printf(“\n ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n”);
printf(” ┃ ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ 圖 書 信 息 管 理 系 統 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ 1.圖書數據輸入 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ 2.圖書數據瀏覽 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ 3.圖書數據查找 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ 4.圖書數據排序 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ 5.圖書數據修改 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ 6.圖書數據刪除 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ 7.退出系統 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ (Alpha Ver 0.1)┃\n”);
printf(” ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n”);
printf(” 請選擇操作:”);
}
int days(int year,int month) /*判斷年月,返回輸入時月份最大天數限制*/
{
int day2,loop=0;
if(year%4==0year%100!=0||year%400==0)
loop=1;
switch(month)
{
case 4:
case 6:
case 9:
case 11:
{
day2=30;
return(day2);
}
break;
case 2:
{
if(loop==1)
{
day2=29;
return(day2);
}
else
{
day2=28;
return(day2);
}
break;
}
break;
default :
{
day2=31;
return(day2);
}
break;
}
}
void input() /*圖書信息輸入函數*/
{
FILE *fp,*fp1;
struct data t;
char ch;
int day1,count,loop,i;
float temp;
do
{
system(“cls”);
fp=fopen(“book.dat”,”ab”);
if(fp==NULL)
{
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n\n\t\t\t\t文件無法創建!”);
getchar();
return;
}
do /*判斷登錄號是否重複及是否小於0*/
{
fp1=fopen(“book.dat”,”rb”);
loop=0;
fseek(fp1,0,2);
count=ftell(fp1)/sizeof(struct data);
fclose(fp1);
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\t請輸入圖書信息:”);
printf(“\n\t\t\t1.登 錄 號:”);
scanf(“%d”,book.num);
getchar();
for(i=0;icount;i++)
{
fp1=fopen(“book.dat”,”rb”);
fseek(fp1,i*(sizeof(struct data)),0);
fread(t,sizeof(struct data),1,fp1);
fclose(fp1);
if(book.num=0)
{
loop=1;
break;
}
if(book.num==t.num)
{
loop=1;
break;
}
}
}while(loop!=0);
printf(“\n\t\t\t2.圖 書 名:”);
scanf(“%s”,book.bname);
printf(“\n\t\t\t3.作 者 名:”);
scanf(“%s”,book.wname);
printf(“\n\t\t\t4.分 類 號:”);
scanf(“%s”,book.clanum);
printf(“\n\t\t\t5.出版單位:”);
scanf(“%s”,book.pubcom);
printf(“\n\t\t\t6.出版時間:”);
printf(“\n\t\t\t 年:”);
scanf(“%d”,book.pubtime.year);
getchar();
while(book.pubtime.year2006||book.pubtime.year=0) /*判斷年份是否超出界限,超出就重新輸入正確值*/
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\t請輸入圖書信息:”);
printf(“\n\t\t\t1.登 錄 號:%d\n”,book.num);
printf(“\n\t\t\t2.圖 書 名:%s\n”,book.bname);
printf(“\n\t\t\t3.作 者 名:%s\n”,book.wname);
printf(“\n\t\t\t4.分 類 號:%s\n”,book.clanum);
printf(“\n\t\t\t5.出版單位:%s\n”,book.pubcom);
printf(“\n\t\t\t6.出版時間:”);
printf(“\n\t\t\t 年:”);
scanf(“%d”,book.pubtime.year);
getchar();
}
printf(“\t\t\t 月:”);
scanf(“%d”,book.pubtime.month);
getchar();
while(book.pubtime.month12||book.pubtime.month=0) /*判斷月份是否超出界限,超出就重新輸入正確值*/
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\t請輸入圖書信息:”);
printf(“\n\t\t\t1.登 錄 號:%d\n”,book.num);
printf(“\n\t\t\t2.圖 書 名:%s\n”,book.bname);
printf(“\n\t\t\t3.作 者 名:%s\n”,book.wname);
printf(“\n\t\t\t4.分 類 號:%s\n”,book.clanum);
printf(“\n\t\t\t5.出版單位:%s\n”,book.pubcom);
printf(“\n\t\t\t6.出版時間:”);
printf(“\n\t\t\t 年:%d”,book.pubtime.year);
printf(“\n\t\t\t 月:”);
scanf(“%d”,book.pubtime.month);
getchar();
}
printf(“\t\t\t 日:”);
scanf(“%d”,book.pubtime.day);
getchar();
day1=days(book.pubtime.year,book.pubtime.month); /*計算輸入年月後,當月的天數最大值*/
while(book.pubtime.dayday1||book.pubtime.day=0) /*判斷天數是否超出界限,超出就重新輸入正確值*/
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\t請輸入圖書信息:”);
printf(“\n\t\t\t1.登 錄 號:%d\n”,book.num);
printf(“\n\t\t\t2.圖 書 名:%s\n”,book.bname);
printf(“\n\t\t\t3.作 者 名:%s\n”,book.wname);
printf(“\n\t\t\t4.分 類 號:%s\n”,book.clanum);
printf(“\n\t\t\t5.出版單位:%s\n”,book.pubcom);
printf(“\n\t\t\t6.出版時間:”);
printf(“\n\t\t\t 年:%d”,book.pubtime.year);
printf(“\n\t\t\t 月:%d”,book.pubtime.month);
printf(“\n\t\t\t 日:”);
scanf(“%d”,book.pubtime.day);
getchar();
}
do /*判斷價格是否為0和負值*/
{
loop=0;
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\t請輸入圖書信息:”);
printf(“\n\t\t\t1.登 錄 號:%d\n”,book.num);
printf(“\n\t\t\t2.圖 書 名:%s\n”,book.bname);
printf(“\n\t\t\t3.作 者 名:%s\n”,book.wname);
printf(“\n\t\t\t4.分 類 號:%s\n”,book.clanum);
printf(“\n\t\t\t5.出版單位:%s\n”,book.pubcom);
printf(“\n\t\t\t6.出版時間:”);
printf(“\n\t\t\t 年:%d”,book.pubtime.year);
printf(“\n\t\t\t 月:%d”,book.pubtime.month);
printf(“\n\t\t\t 日:%d”,book.pubtime.day);
printf(“\n\n\t\t\t7.價 格:”);
scanf(“%f”,temp);
book.price=temp;
if(book.price=0)
{
loop=1;
}
}while(loop!=0);
fwrite(book,sizeof(struct data),1,fp);
fclose(fp);
printf(“\n\t\t\t\t\t\t是否繼續輸入數據(Y or N)?:”);
ch=getch();
}while(ch==’y’||ch==’Y’);
system(“cls”);
getchar();
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n 圖書信息輸入結束!”);
printf(“\n\n\n\n Press ENTER to continue!”);
getchar();
}
void output()
{
FILE *fp;
int count,i;
char ch;
fp=fopen(“book.dat”,”rb”);
if(fp==NULL)
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 瀏 覽 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n\n\t\t\t\t文件無法讀取!”);
getchar();
return;
}
fseek(fp,0,2);
count=ftell(fp)/sizeof(struct data); /*讀取文件里的記錄條數*/
rewind(fp);
if(count==0)
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 瀏 覽 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n\n\t\t\t\t圖書庫內無信息!”);
getchar();
return;
}
for(i=0;icount;i++)
fread(books[i],sizeof(struct data),1,fp); /*將文件中的數據讀取到內存中*/
fclose(fp);
for(i=0;icount;)
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 瀏 覽 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\t瀏覽圖書信息:”);
printf(“\n\t\t\t1.登 錄 號:%d\n”,books[i].num);
printf(“\n\t\t\t2.圖 書 名:%s\n”,books[i].bname);
printf(“\n\t\t\t3.作 者 名:%s\n”,books[i].wname);
printf(“\n\t\t\t4.分 類 號:%s\n”,books[i].clanum);
printf(“\n\t\t\t5.出版單位:%s\n”,books[i].pubcom);
printf(“\n\t\t\t6.出版時間:%d年%d月%d日\n”,books[i].pubtime.year,books[i].pubtime.month,books[i].pubtime.day);
printf(“\n\t\t\t7.價 格:%.2f\n”,books[i].price);
if(i==0count==1) /*當記錄只有1條時顯示菜單選項*/
{
printf(“\n\n\t1.返回主菜單”);
printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);
printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);
}
else if(count1) /*記錄大於1條*/
{
if(i==0) /*首頁的顯示菜單*/
{
printf(“\n\n\t1.返回主菜單\t2.下一頁”);
printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);
printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);
}
else if(i==count-1) /*末頁的顯示菜單*/
{
printf(“\n\n\t1.返回主菜單\t\t\t3.上一頁”);
printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);
printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);
}
else /*中間頁的顯示菜單*/
{
printf(“\n\n\t1.返回主菜單\t2.下一頁\t3.上一頁”);
printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);
printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);
}
}
ch=getchar();
getchar();
if(ch==’1′)
break;
if(ch==’2′)
{
if(i!=count-1) /*記錄不為末頁時向下翻頁*/
i++;
else /*記錄為末頁時的下翻處理,防止超出界限*/
{
getchar();
getchar();
}
}
if(ch==’3′)
{
if(i!=0) /*記錄不為首頁時向上翻頁*/
i–;
else /*記錄為首頁時的上翻處理,防止超出界限*/
{
getchar();
getchar();
}
}
}
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 瀏 覽 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n 圖書信息瀏覽結束!”);
printf(“\n\n\n\n Press ENTER to continue!”);
getchar();
}
void find()
{
FILE *fp;
struct data temp[20];
int count,i,n;
char ch,ch1,ch2,cha[20];
fp=fopen(“book.dat”,”rb”);
if(fp==NULL)
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n\n\t\t\t\t文件無法讀取!”);
getchar();
return;
}
fseek(fp,0,2);
n=ftell(fp)/sizeof(struct data);
rewind(fp);
for(i=0;in;i++)
fread(books[i],sizeof(struct data),1,fp);
fclose(fp);
if(n==0)
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n\n\t\t\t\t圖書庫內無信息!”);
getchar();
return;
}
do
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\t\t\t1.按圖書名查詢”);
printf(“\n\n\n\t\t\t2.按作者名查詢”);
printf(“\n\n\n\t\t\t3.退出查詢”);
printf(“\n\n\n\t\t\t\t請選擇相應的操作:”);
ch1=getchar();
getchar();
if(ch1==’1′)
{
do
{
count=0;
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\t\t請輸入查詢的圖書名:”);
scanf(“%s”,cha); /*輸入查詢內容*/
getchar();
for(i=0;in;i++)
{
if(strstr(books[i].bname,cha)) /*查詢*/
{
temp[count]=books[i]; /*將找到匹配數據放入臨時變量*/
count++; /*統計查找到的記錄條數*/
}
}
if(count==0)
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\t\t\t\t未查找到相關數據!!!”);
printf(“\n\n\n\n\n\t\t\t\t\t\t是否繼續查詢?(Y or N):”);
ch2=getchar();
getchar();
}
}while(count==0ch2==’y’||ch2==’Y’);
for(i=0;icount;) /*瀏覽匹配數據*/
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\t瀏覽圖書信息:”);
printf(“\n\t\t\t1.登 錄 號:%d\n”,temp[i].num);
printf(“\n\t\t\t2.圖 書 名:%s\n”,temp[i].bname);
printf(“\n\t\t\t3.作 者 名:%s\n”,temp[i].wname);
printf(“\n\t\t\t4.分 類 號:%s\n”,temp[i].clanum);
printf(“\n\t\t\t5.出版單位:%s\n”,temp[i].pubcom);
printf(“\n\t\t\t6.出版時間:%d年%d月%d日\n”,temp[i].pubtime.year,temp[i].pubtime.month,temp[i].pubtime.day);
printf(“\n\t\t\t7.價 格:%.2f\n”,temp[i].price);
if(i==0count==1)
{
printf(“\n\n\t1.返回主菜單”);
printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);
printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);
}
else if(count1)
{
if(i==0)
{
printf(“\n\n\t1.返回主菜單\t2.下一頁”);
printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);
printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);
}
else if(i==count-1)
{
printf(“\n\n\t1.返回主菜單\t\t\t3.上一頁”);
printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);
printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);
}
else
{
printf(“\n\n\t1.返回主菜單\t2.下一頁\t3.上一頁”);
printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);
printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);
}
}
ch=getchar();
getchar();
if(ch==’1′)
break;
if(ch==’2′)
{
if(i!=count-1)
i++;
else
{
getchar();
getchar();
}
}
if(ch==’3′)
{
if(i!=0)
i–;
else
{
getchar();
getchar();
}
}
}
}
if(ch1==’2′)
{
do
{
count=0;
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\t\t請輸入查詢的作者名:”);
scanf(“%s”,cha); /*輸入查詢內容*/
getchar();
for(i=0;in;i++)
{
if(strstr(books[i].wname,cha)) /*數據比較*/
{
temp[count]=books[i]; /*將找到匹配數據放入臨時變量*/
count++; /*統計查找到的記錄條數*/
}
}
if(count==0)
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\t\t\t\t未查找到相關數據!!!”);
printf(“\n\n\n\n\n\t\t\t\t\t\t是否繼續查詢?(Y or N):”);
ch2=getchar();
getchar();
}
}while(count==0ch2==’y’||ch2==’Y’);
for(i=0;icount;) /*瀏覽匹配數據*/
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\t瀏覽圖書信息:”);
printf(“\n\t\t\t1.登 錄 號:%d\n”,temp[i].num);
printf(“\n\t\t\t2.圖 書 名:%s\n”,temp[i].bname);
printf(“\n\t\t\t3.作 者 名:%s\n”,temp[i].wname);
printf(“\n\t\t\t4.分 類 號:%s\n”,temp[i].clanum);
printf(“\n\t\t\t5.出版單位:%s\n”,temp[i].pubcom);
printf(“\n\t\t\t6.出版時間:%d年%d月%d日\n”,temp[i].pubtime.year,temp[i].pubtime.month,temp[i].pubtime.day);
printf(“\n\t\t\t7.價 格:%.2f\n”,temp[i].price);
if(i==0count==1)
{
printf(“\n\n\t1.返回主菜單”);
printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);
printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);
}
else if(count1)
{
if(i==0)
{
printf(“\n\n\t1.返回主菜單\t2.下一頁”);
printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);
printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);
}
else if(i==count-1)
{
printf(“\n\n\t1.返回主菜單\t\t\t3.上一頁”);
printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);
printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);
}
else
{
printf(“\n\n\t1.返回主菜單\t2.下一頁\t3.上一頁”);
printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);
printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);
}
}
ch=getchar();
getchar();
if(ch==’1′)
break;
if(ch==’2′)
{
if(i!=count-1)
i++;
else
{
getchar();
getchar();
}
}
if(ch==’3′)
{
if(i!=0)
i–;
else
{
getchar();
getchar();
}
}
}
}
}while(ch1!=’3′);
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n 圖書信息查詢結束!”);
printf(“\n\n\n\n Press ENTER to continue!”);
getchar();
}
void sort()
{
FILE *fp;
int n,i,j;
fp=fopen(“book.dat”,”rb”);
if(fp==NULL)
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 排 序 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n\n\t\t\t\t文件無法讀取!”);
getchar();
return;
}
fseek(fp,0,2);
n=ftell(fp)/sizeof(struct data);
rewind(fp);
for(i=0;in;i++)
fread(books[i],sizeof(struct data),1,fp);
fclose(fp);
if(n==0)
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 排 序 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n\n\t\t\t\t圖書庫內無信息!”);
getchar();
return;
}
for(i=0;in-1;i++) /*排序*/
{ for(j=0;j(n-1)-i;j++)
{
if(books[j].numbooks[j+1].num)
{
book=books[j];
books[j]=books[j+1];
books[j+1]=book;
}
}
}
fp=fopen(“book.dat”,”wb”); /*將排序內容重新寫入文件*/
for(i=0;in;i++)
fwrite(books[i],sizeof(struct data),1,fp);
fclose(fp);
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 排 序 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n\n\n\t\t\t\t已按圖書登錄號排序完畢!!!”);
getchar();
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 排 序 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n 圖書信息排序結束!”);
printf(“\n\n\n\n Press ENTER to continue!”);
getchar();
}
void edit()
{
FILE *fp,*fp1;
struct data temp[20];
int i,n,count,k[20],day1,loop,count1,j;
float t1;
char cha[20],ch,ch1,ch2;
fp=fopen(“book.dat”,”rb”);
if(fp==NULL)
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 修 改 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n\n\t\t\t\t文件無法讀取!”);
getchar();
return;
}
fseek(fp,0,2);
n=ftell(fp)/sizeof(struct data);
rewind(fp);
for(i=0;in;i++)
fread(books[i],sizeof(struct data),1,fp);
fclose(fp);
if(n==0)
{
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 修 改 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\n\n\t\t\t\t圖書庫內無信息!”);
getchar();
return;
}
do
{
count=0;
system(“cls”);
printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 修 改 ※ ※ ※ ※ ※ ※\n”);
printf(“\n\n\n\t\t請輸入要修改的圖書名:”);
scanf(“%s”,cha);
getchar();
for(i=0;in;i++)
{
if(strstr(books[i].bname,cha))
{
temp[count]=books[i]; /*源代碼太長發不完,你要的話留下Email和懸賞分偶跟你發過去 */
k[count]=i;
count++;
}
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/206330.html