//複合文字 #include<stdio.h> #define MAXTITL 41 #define MAXAUTL 31 struct book { char title[MAXTITL]; char author[MAXAUTL]; float value; }; int main(void) { struct book readFirst; int score; printf("Enter test score:"); scanf("%d",&score); if(score >= 84) { readFirst = (struct book) {"Crime and Punishment", "Fyodor Dostoyevsky", 9.99 }; } else { readFirst = (struct book) {"Mr.Bouncy's NIce Hat", "Fred Winsome", 5.99 }; } printf("Your assigned reading:/n"); printf("%s by %s $%.2f/n",readFirst.title, readFirst.author,readFirst.value); return 0; }
//伸縮數組成員 #include<stdio.h> #include<stdlib.h> struct flex { int count; double average; double scores[]; }; void showFlex(const struct flex * p); int main(void) { struct flex *pf1, *pf2; int n = 5; int i; int tot = 0; /*爲結構和數組分配空間*/ pf1 = malloc(sizeof (struct flex) + n * sizeof(double)); pf1->count = n; for(i = 0; i < n; i++) { pf1->scores[i] = 20.0-i; tot += pf1->scores[i]; } pf1->average = tot / n; showFlex(pf1); n = 9; tot = 0; pf2 = malloc(sizeof(struct flex) + n * sizeof(double)); pf2->count = n; for(i = 0; i < n; i++) { pf2->scores[i] = 20.0 - i/2.0; tot += pf2->scores[i]; } pf2->average = tot / n; showFlex(pf2); free(pf1); free(pf2); getch(); return 0; } void showFlex(const struct flex *p) { int i; printf("Scores:"); for(i = 0; i < p->count; i++) { printf("%g",p->scores[i]); } printf("/n Average :%g/n",p->average); }
//把結構保存到文件中 #include<stdio.h> #include<stdlib.h> #define MAXTITL 40 #define MAXAUTL 40 #define MAXBKS 10 struct book { char title[MAXTITL]; char author[MAXAUTL]; float value; }; int main(void) { struct book library[MAXBKS]; int count = 0; int index,filecount; FILE * pbooks; int size = sizeof(struct book); if((pbooks = fopen("book.dat","a+b"))==NULL) { fputs("Can't open book.dat file./n",stderr); exit(1); } rewind(pbooks); while(count < MAXBKS && fread(&library[count],size, 1,pbooks) == 1) { if(count = 0) { puts("Current contentd of bool.dat"); } printf("%s by %s $%.2f/n",library[count].title, library[count].author,library[count].value); count++; } filecount = count; if(count == MAXBKS) { fputs("The book.dat file is full./n",stderr); exit(2); } puts("Please add new book title./n"); puts("Please[enter] at the start of a line to stop./n"); while(count < MAXBKS && gets(library[count].title) != NULL && library[count].title[0] != '/0') { puts("Now enter the author."); gets(library[count].author); puts("Now enter the value."); scanf("%f",&library[count++].value); while(getchar() != '/n') { continue; } if(count < MAXBKS) { puts("Enter the next title."); } } if(count > 0) { puts("Here is the list of your books:"); for(index = 0; index < count; index++) { printf("%s by %s: $%.2f/n",library[index].title, library[index].author,library[index].value); } fwrite(&library[filecount],size,count - filecount,pbooks); } else { puts("No books?Too bad./n"); } puts("Bye./n"); fclose(pbooks); getch(); return 0; }
//enum #include<stdio.h> #include<string.h> #include<stdbool.h> enum spectrum {red,orange,yellow,green,blue,violet}; const char *colors[] = {"red","orange","yellow","green", "blue","violet"}; #define LEN 30 int main(void) { char choice[LEN]; enum spectrum color; bool colorIsfound = false; puts("Enter a color (empty line to quit):"); while(gets(choice) != NULL && choice[0] != '/0') { for(color = red; color <= violet; color++) { if(strcmp(choice,colors[color]) == 0) { colorIsfound = true; break; } } if(colorIsfound) { switch(color) { case red :puts("Roses are red."); break; case orange:puts("Poppies are orange."); break; case yellow:puts("Sunflowers are yellow."); break; case green :puts("Grass are green."); break; case blue :puts("Bluebells are blue,"); break; case violet:puts("Violets are violet,"); break; } } else { printf("I don't know about the color %s./n",choice); } colorIsfound = false; puts("Next color.please(empty line to quit):"); } puts("Goodbye!"); getch(); return 0; }
//函數指針 #include<stdio.h> #include<string.h> #include<ctype.h> char showmenu(void); void eatline(void);//讀至行末 void show(void (*fp)(char *),char *str); void ToUpper(char *);//轉換爲大寫 void ToLower(char *);//轉換爲小寫 void Transpose(char *);//大小寫轉置 void Dummy(char *);//不改變字符串 int main(void) { char line[81]; char copy[81]; char choice; void (*pfun)(char *);/*指向一個函數,該函數接受一個字符指針,沒返回值*/ puts("Enter a string(empty line to quit):"); while(gets(line) != NULL &&line[0] != '/0') { while((choice = showmenu()) != 'n') { switch(choice)//switch語句用來設置指針 { case 'u':pfun = ToUpper; break; case 'l':pfun = ToLower; break; case 't':pfun = Transpose; break; case 'o':pfun = Dummy; break; } strcpy(copy,line);//爲show()製作一個備份 show(pfun,copy); //使用用戶選擇的函數 } puts("Enter a string(empty line to quit):"); } puts("Bye"); getch(); return 0; } char showmenu(void) { char ans; puts("Enter menu choice."); puts("u)uppercase l)lowercase"); puts("t)transposed case o)original case"); puts("n)next string"); ans = getchar();//獲取用戶的響應 ans = tolower(ans);//轉換爲小寫 eatline();// 刪除行中剩餘部分 while(strchr("ulton",ans) == NULL) { puts("PLease enter a u,l t, o, or n:"); ans = tolower(getchar()); eatline(); } return ans; } void eatline(void) { while(getchar() != '/n') continue; } void ToUpper(char *str) { while(*str) { *str = toupper(*str); str++; } } void ToLower(char *str) { while(*str) { *str = tolower(*str); str++; } } void Transpose(char *str) { while(*str) { if(islower(*str)) *str = toupper(*str); else if(isupper(*str)) *str = tolower(*str); str++; } } void Dummy(char *str) { //不改變字符串 } void show(void(*fp)(char *),char *str) { (*fp)(str);//把用戶選擇的函數作用於str puts(str);//顯示結果 }
一、前言 當涉及到敏感數據的導出和共享時,數據安全是至關重要的。在現代數字化時代,保護個人和機密信息免受未經授權的訪問和竊取是每個組織和個人的首要任務之一。在這種背景下,葡萄城的純前端表格控件 SpreadJS 提供的加密功能爲用戶提供了一
docker run -p 9000:9000 -p 9001:9001 --name minio -d --restart=always -e "MINIO_ACCESS_KEY=admin" -e "MINIO_SECRET_KEY=a
how to configure multiple domain (virtual host) and multiple virtual port # start the nginx proxy docker run -d -p 80:80
前言 今天大姚給大家分享一個由微軟官方開源(MIT License)、免費的Blazor UI組件庫:Fluent UI Blazor。 全面的ASP.NET Core Blazor簡介和快速入門 Fluent UI Blazor介紹
前言 最近經常在DotNetGuide技術社區交流羣裏看到有小夥伴問:有什麼好用的.NET定時任務調度框架推薦的?有什麼好的WPF/WinForm/Blazor圖表庫推薦的?.NET好用的後臺管理框架有推薦的嗎?大家平時都是怎麼找.NET
排列序列 已解答 困難 相關標籤 相關企業 給出集合 [1,2,3,...,n],其所有元素共有 n! 種排列。 按大小順序列出所有排列情況,並一一標記,當 n = 3 時, 所有排列如下: "123" "132" "213" "231
ipvsadm命令 沒想到自己之前二進制部署的,也是ipvs代理模式 node2上沒有裝ipvs,也看不了一些ipvs規則 node1上安裝ipvsadm,然後就可以看的k8s添加的規則了 yum install ipvsadm
關於從零設計 .NET 開發框架 作者:癡者工良 教程說明: 倉庫地址:https://github.com/whuanle/maomi 文檔地址:https://maomi.whuanle.cn 作者博客: https://www.whu
2024-06-03 index word pronunciation parts of speech explanation translation in Chinese 1 fuss /fʌs/ noun/verb unnec
2024-06-302024-06-292024-06-282024-06-272024-06-262024-06-252024-06-242024-06-232024-06-222024-06-212024-06-202024-06-19
初探富文本之基於虛擬滾動的大型文檔性能優化方案 虛擬滾動是一種優化長列表性能的技術,其通過按需渲染列表項來提高瀏覽器運行效率。具體來說,虛擬滾動只渲染用戶瀏覽器視口部分的文檔數據,而不是整個文檔結構,其核心實現根據可見區域高度和容器的滾動位
ReZero AP ReZero是一款.NET中間件 : 一款通過界面操作就能生成API , 可以集成到任何.NET6+ API項目,無破壞性,也可讓非.NET用戶使用exe文件 ReZero生成器功能簡介 1、表文檔導出:支持目錄導航
Microsoft.Extensions.DependencyInjection中(下面簡稱DI),在調用ServiceProvider和IServiceScope對象的Dispose()方法時,也會自動調用ServiceProvider和
對於“軟件架構”這個詞有很多定義和含義。而且,“軟件開發”、“軟件設計”和“軟件架構”這三個概念之間存在相當大的重疊,它們在許多方面相互交融。 從核心上看,可以將軟件架構視爲在構建應用程序時,對不同選擇進行權衡的學科。 1 爲什麼需要權衡以
Node.js是一個基於 Chrome V8 引擎的 JavaScript 運行環境。Node.js 使用了一個事件驅動、非阻塞式 I/O 的模型,使其輕量又高效。Express是一個保持最小規模的靈活的 Node.js Web應用程序開發