-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
416f263
commit caa5ae9
Showing
127 changed files
with
1,887 additions
and
342 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file added
BIN
+129 KB
.vs/learn_c_primer.github.io/FileContentIndex/1622eca0-07a7-407b-8740-d6f90028fb7d.vsidx
Binary file not shown.
Binary file added
BIN
+16 KB
.vs/learn_c_primer.github.io/FileContentIndex/3e3b97c0-f4d4-42a6-b009-25771b2e5f32.vsidx
Binary file not shown.
Binary file added
BIN
+13.6 KB
.vs/learn_c_primer.github.io/FileContentIndex/832177d5-e44d-4618-aa0e-6ffcae2c4d7b.vsidx
Binary file not shown.
Binary file removed
BIN
-8.14 KB
.vs/learn_c_primer.github.io/FileContentIndex/921ce8bd-09f6-46d4-814e-b0fc9f8e8b59.vsidx
Binary file not shown.
Binary file removed
BIN
-61.9 KB
.vs/learn_c_primer.github.io/FileContentIndex/a12ba736-83f9-4f30-8097-222521740032.vsidx
Binary file not shown.
Binary file removed
BIN
-11.4 KB
.vs/learn_c_primer.github.io/FileContentIndex/b3783a32-0885-4410-aea1-e6e3db8da096.vsidx
Binary file not shown.
Binary file added
BIN
+842 KB
.vs/learn_c_primer.github.io/FileContentIndex/bc19afe7-6b45-4ff6-8ddb-38bc7313d95f.vsidx
Binary file not shown.
Binary file removed
BIN
-859 KB
.vs/learn_c_primer.github.io/FileContentIndex/eba7fb23-5976-4391-8298-e19075675971.vsidx
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+768 KB
(130%)
.vs/learn_c_primer.github.io/v17/ipch/AutoPCH/2eb5f2e3dd4f02ff/13.12.ipch
Binary file not shown.
Binary file modified
BIN
+576 KB
(120%)
.vs/learn_c_primer.github.io/v17/ipch/AutoPCH/9485adcda53602b5/13.12.ipch
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//加强版; | ||
#include "s_gets.h" | ||
#define MAXTITL 30 | ||
#define MAXBK 100 | ||
//声明结构; | ||
struct book | ||
{ | ||
char title[MAXTITL], author[MAXTITL]; | ||
float value; | ||
}; | ||
|
||
int main (void) | ||
{ | ||
//声明结构变量; | ||
struct book library[MAXBK], * lib; | ||
int j = 0; | ||
char ch; | ||
|
||
lib = library; | ||
printf ("Please enter the book title. \n"); | ||
printf ("While less than 30 books, enter an empty line anytime to quit. \n"); | ||
|
||
//逐个存入书籍信息并在循环中存入title, 如果用户按下回车则结束任务, 注意指针使用方法; | ||
for (; (j < MAXBK) && (s_gets_1 (lib -> title, MAXTITL)) && (lib -> title[0]); j ++, lib ++) | ||
{ | ||
//存入author; | ||
printf ("Please enter the author. \n"); | ||
if (!(s_gets_1 (library[j].author, MAXTITL)) || (!library[j].author[0])) | ||
{ | ||
break; | ||
} | ||
|
||
//存入value; | ||
printf ("Now enter the value. \n"); | ||
//如果读到'\n'则结束任务, 如果不是则将刚刚读到的字符放回输入流; | ||
if ((ch = getchar()) == '\n') | ||
{ | ||
break; | ||
} | ||
ungetc (ch, stdin); | ||
//如果读到非数字则要求输入数字并清空缓冲区; | ||
while (!(scanf ("%f", &library[j].value))) | ||
{ | ||
printf ("Please enter a number. \n"); | ||
fflush (stdin); | ||
} | ||
getchar(); | ||
|
||
printf ("Please enter next book title: \n"); | ||
} | ||
|
||
//打印; | ||
if (j == 0) | ||
{ | ||
printf ("No input. \n"); | ||
return 1; | ||
} | ||
|
||
for (int p1 = 0; p1 < 80; p1 ++) | ||
{ | ||
putchar ('-'); | ||
} | ||
putchar ('\n'); | ||
for (int p = 0; p < j; p ++) | ||
{ | ||
printf ("| %-29s| %-29s| $%-14.2f|\n", library[p].title, library[p].author, library[p].value); | ||
for (int p1 = 0; p1 < 80; p1 ++) | ||
{ | ||
putchar ('-'); | ||
} | ||
putchar ('\n'); | ||
} | ||
|
||
printf ("\nDone. \n"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
//如下声明的结构具备伸缩特性, 该结构不能直接拷贝, 须使用memcpy()进行拷贝; | ||
struct flex | ||
{ | ||
int count; | ||
double average; | ||
double scores[]; | ||
}; | ||
|
||
int main (void) | ||
{ | ||
struct flex * pf = malloc (sizeof (struct flex) + 5 * sizeof (double)); | ||
struct flex * asdf = malloc (sizeof (struct flex) + 9 * sizeof (double)); | ||
|
||
printf ("please enter 5 numbers. \n"); | ||
for (int j = 0; j < 5; j ++) | ||
{ | ||
scanf ("%lf", &pf -> scores[j]); | ||
} | ||
for (int p = 0; p < 5; p ++) | ||
{ | ||
printf ("%lf ", pf -> scores[p]); | ||
} | ||
putchar ('\n'); | ||
|
||
printf ("please enter 9 numbers. \n"); | ||
for (int j = 0; j < 9; j ++) | ||
{ | ||
scanf ("%lf", &asdf -> scores[j]); | ||
} | ||
for (int p = 0; p < 9; p ++) | ||
{ | ||
printf ("%lf ", asdf -> scores[p]); | ||
} | ||
putchar ('\n'); | ||
|
||
free (pf); | ||
free (asdf); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
struct flex | ||
{ | ||
size_t count; | ||
double average; | ||
double scores []; | ||
}; | ||
|
||
void showFlex (const struct flex * p); | ||
|
||
int main (void) | ||
{ | ||
struct flex * pf1, * pf2; | ||
int n = 5, i, 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 / (float)2; //此处 "/ 2" 和 "/ 2.0" 会得到不同结果; | ||
tot += (pf2 -> scores[i]); | ||
} | ||
(pf2 -> average) = tot / n; | ||
showFlex (pf2); | ||
|
||
free (pf1); | ||
free (pf2); | ||
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 ("\nAverage: %g\n", (p -> average)); | ||
} |
Oops, something went wrong.