Skip to content

Commit

Permalink
upload 2.19
Browse files Browse the repository at this point in the history
  • Loading branch information
TGSpock123 committed Feb 19, 2024
1 parent bc7f5ce commit c71f09a
Show file tree
Hide file tree
Showing 46 changed files with 2,087 additions and 201 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified 11/.DS_Store
Binary file not shown.
5 changes: 2 additions & 3 deletions 11/11/11.49.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "s_gets.h"
char str[80];
char * c;
int main (int argc, char * argv[])
{
char str[80];
char * c;

printf ("please enter a sentence. \n");
s_gets (str, 80);
if (argc < 2 || !strcmp (argv[1], "-p"))
Expand Down
23 changes: 23 additions & 0 deletions 12/12.1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
//一个写代码让人看不懂的小技巧.
int main (void)
{
int x = 30; //原始 x, 函数内通用, 不会被块内的 x 更改值.

printf ("x in outer block: %d at %p\n", x, &x);
{
int x = 77; //定义在块内, 离开块时被销毁.
printf ("x in inner block: %d at %p\n", x, &x);
}
printf ("x in outer block: %d at %p\n", x, &x);
while (x ++ < 33)
{
int x = 100; //定义在 while 块内.
x ++;
printf ("x in while loop: %d at %p\n", x, &x);
}
//每次离开循环时, while 中的 x 被销毁, 进入时被重新定义.
printf ("x in outer block: %d at %p\n", x, &x);

return 0;
}
6 changes: 6 additions & 0 deletions 12/12.10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>
int main (void)
{

return 0;
}
20 changes: 20 additions & 0 deletions 12/12.2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
int main (void)
{
int n = 8;

printf ("Intially, n = %d at %p\n", n, &n);
for (int n = 1; n < 3; n ++)
printf ("loop 1: n = %d at %p\n", n, &n);
printf ("After loop 1, n = %d at %p\n", n, &n);
for (int n = 1; n < 3; n ++)
{
printf ("loop 2 index n = %d at %p\n", n, &n);
int n = 6;
printf ("loop 2: n = %d at %p\n", n, &n);
n ++;
printf ("loop 2 - 2: n = %d at %p\n", n, &n);
}
printf ("After loop 2, n = %d at %p\n", n, &n);
return 0;
}
20 changes: 20 additions & 0 deletions 12/12.3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
int fade = 1;
void trystat (void);
int main (void)
{
int count;
for (count = 1; count <= 3; count ++)
{
printf ("Here comes iteration %d: \n", count);
trystat ();
}

return 0;
}
void trystat (void)
{
static int stay = 1;

printf ("fade = %d and stay = %d\n", fade ++, stay ++);
}
12 changes: 12 additions & 0 deletions 12/12.4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>
//extern 使用方法
void swe (void);
int main (void)
{
extern int coal;

printf ("%d\n", coal);
swe();

return 0;
}
2 changes: 2 additions & 0 deletions 12/12.4_5.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <stdio.h>
int coal = 6;
11 changes: 11 additions & 0 deletions 12/12.5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "12.4_5.h"
static int i = 0;
extern void swe (void)
{
extern int coal;

for ( ; i < coal; i ++)
{
printf ("hello c world\n");
}
}
48 changes: 48 additions & 0 deletions 12/12.6.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <stdio.h>
//示例1:
int hocus;
int magic ();
int main (void)
{
extern int hocus;
...
}
int magic ()
{
extern int hocus;
...
}
//上文中一共出现了一个hocus, 后面两次声明起强调作用, 可以省略.
//示例2:
int hocus;
int magic (void);
int main (void)
{
extern int hocus;
...
}
int magic (void)
{
//未声明变量
...
}
//示例2中出现两个hocus, 第一个是文件头部的全局hocus变量, 第二个是main函数里的局部hocus变量.
//全局hocus变量对main函数不可见, 因为被局部hocus变量挡住了.
//虽然magic函数没有声明hocus变量, 它可以调用头部的全局hocus变量.
//示例3:
int hocus;
int magic (void);
int main (void)
{
int hocus;//默认被声明为自动变量.
...
}
int pocus;//因为它被声明在了main函数后面, 所以它虽然全局存在但对main函数不可见.
int magic (void)
{
auto int hocus;//现实声明为自动变量, 效果和上面差不多.
...
}
//示例3中一共出现四个变量, 全局变量hocus, main函数中局部变量hocus,
//magic函数中局部变量hocus和对main函数不可见的全局变量pocus.
//全局变量对main函数和magic函数均不可见.
22 changes: 22 additions & 0 deletions 12/12.7.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
int units = 0;
void critic (void);
int main (void)
{
extern int units;

printf ("how many pounds to firkin of butter? \n");
scanf ("%d", &units);
while (units != 56)
{
critic ();
}
printf ("you must have looked it up. \n");

return 0;
}
void critic (void)
{
printf ("no luck, my friend. try again. \n");
scanf ("%d", &units);
}
23 changes: 23 additions & 0 deletions 12/12.8.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
void report_count();
void accumulate(int k);
int count = 0;
int main (void)
{
int value;
register int i;

printf ("enter a positive integer (0 to quit): \n");
while (scanf ("%d", &value) == 1 && value > 0)
{
++ count;
for (i = value; i >= 0; i --)
{
accumulate (i);
}
printf ("enter a positive integer (0 to quit): \n");
}
report_count ();

return 0;
}
22 changes: 22 additions & 0 deletions 12/12.9.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
extern int count;
static int total = 0;
void accumulate (int k)
{
static int subtotal = 0;

if (k <= 0)
{
printf ("loop cycle: %d\n", count);
printf ("subtotal: %d; total: %d\n", subtotal, total);
subtotal = 0;
}else
{
subtotal += k;
total += k;
}
}
void report_count ()
{
printf ("loop executed %d times. \n", count);
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
}
],
"type" : "INTERNAL",
"value" : "0"
"value" : "8"
},
{
"name" : "CMAKE_COLOR_DIAGNOSTICS",
Expand Down Expand Up @@ -190,7 +190,7 @@
"value" : "C compiler"
}
],
"type" : "FILEPATH",
"type" : "STRING",
"value" : "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc"
},
{
Expand Down
Loading

0 comments on commit c71f09a

Please sign in to comment.