-
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
2a97ee2
commit b370688
Showing
23 changed files
with
350 additions
and
4 deletions.
There are no files selected for viewing
Binary file modified
BIN
-639 Bytes
(99%)
...odeproj/project.xcworkspace/xcuserdata/tgspock.xcuserdatad/UserInterfaceState.xcuserstate
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
+15.8 KB
(200%)
...odeproj/project.xcworkspace/xcuserdata/tgspock.xcuserdatad/UserInterfaceState.xcuserstate
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,29 @@ | ||
#include <stdio.h> | ||
int main (void) | ||
{ | ||
char words[10]; | ||
int i = 0; | ||
|
||
puts ("Enter strings(empty line to quit):"); | ||
while (fgets (words, 10, stdin) != NULL && words[0] != '\n') | ||
{ | ||
while (words[i] != '\n' && words[i] != '\0') | ||
{ | ||
i ++; | ||
} | ||
if (words[i] == '\n') | ||
{ | ||
words[i] = '\0'; | ||
}else | ||
{ | ||
while (getchar() != '\n') | ||
{ | ||
continue; | ||
} | ||
} | ||
puts (words); | ||
} | ||
puts ("done"); | ||
|
||
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,19 @@ | ||
// | ||
// 11.11.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/8. | ||
// | ||
|
||
#include <stdio.h> | ||
int main (void) | ||
{ | ||
char name1[11], name2[11]; | ||
int count; | ||
|
||
printf ("Please enter 2 names.\n"); | ||
count = scanf ("%5s %10s", name1, name2); | ||
printf ("I read %d names %s and %s.\n", count, name1, name2); | ||
|
||
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,23 @@ | ||
// | ||
// 11.12.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/8. | ||
// | ||
|
||
#include <stdio.h> | ||
#define DEF "I am a #defined string." | ||
int main (void) | ||
{ | ||
char str1[80] = "An array was initialized to me. "; | ||
const char *str2 = "A pointer was initialized to me. "; | ||
|
||
puts ("I am an argument to puts(). "); | ||
puts (DEF); | ||
puts (str1); | ||
puts (str2); | ||
puts (&str1[5]); | ||
puts (str2 +4); | ||
|
||
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,19 @@ | ||
// | ||
// 11.13.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/8. | ||
// | ||
|
||
#include <stdio.h> | ||
int main (void) | ||
{ | ||
char side_a[] = "Side A"; | ||
char dont[] = {'W', 'O', 'W', '!'}; | ||
char side_b[] = "Side B"; | ||
|
||
printf ("side_a = %p, dont = %p, side_b[] = %p\n", side_a, dont, side_b); | ||
puts (dont); | ||
|
||
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,28 @@ | ||
// | ||
// 11.14.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/8. | ||
// | ||
|
||
#include <stdio.h> | ||
int main (void) | ||
{ | ||
char line[8]; | ||
int i; | ||
|
||
printf ("Now puts() speaking: \n"); | ||
while (gets (line) && line[0] != EOF) | ||
{ | ||
i = 0; | ||
puts (line); | ||
} | ||
printf ("Now fputs() speaking: \n"); | ||
while (fgets (line, 8, stdin) && line[0] != '\n') | ||
{ | ||
i = 0; | ||
fputs (line, stdout); | ||
} | ||
|
||
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,8 @@ | ||
// | ||
// 11.15.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/9. | ||
// | ||
|
||
#include <stdio.h> |
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,14 @@ | ||
// | ||
// 11.2.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/2. | ||
// | ||
|
||
#include <stdio.h> | ||
int main (void) | ||
{ | ||
printf ("%s, %p, %c\n", "We", "are", *"space farers"); | ||
|
||
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,22 @@ | ||
// | ||
// 11.3.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/2. | ||
// | ||
|
||
#define MSG "I'm special" | ||
#include <stdio.h> | ||
int main (void) | ||
{ | ||
char ar[] = MSG; | ||
const char * pt = MSG; | ||
|
||
printf ("address of \"I'm special\": %p \n", "I'm special"); | ||
printf (" address ar: %p \n", ar); | ||
printf (" address pt: %p \n", pt); | ||
printf (" address of MSG: %p \n", MSG); | ||
printf ("address of \"I'm special\": %p \n", "I'm special"); | ||
|
||
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,60 @@ | ||
// | ||
// 11.4.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/2. | ||
// | ||
|
||
#include <stdio.h> | ||
int main (void) | ||
{ | ||
char heart[] = "I love A"; | ||
const char * head = "I love B"; | ||
const char * spare; | ||
|
||
printf ("address heart = %p\n", heart); | ||
printf ("address head = %p\n", head); | ||
printf ("address spare = %p\n", spare); | ||
for (int i = 0; i < 8; i ++) | ||
{ | ||
putchar (heart[i]); | ||
} | ||
putchar ('\n'); | ||
for (int i = 0; i < 8; i ++) | ||
{ | ||
putchar (head[i]); | ||
} | ||
putchar ('\n'); | ||
for (int i = 0; i < 8; i ++) | ||
{ | ||
putchar (*(heart + i)); | ||
} | ||
putchar ('\n'); | ||
for (int i = 0; i < 8; i ++) | ||
{ | ||
putchar (*(head + i)); | ||
} | ||
putchar ('\n'); | ||
while (*(head) != '\0') | ||
{ | ||
putchar (*(head++)); | ||
} | ||
putchar ('\n'); | ||
printf ("address head b4 = %p \n", head); | ||
head = heart; | ||
printf ("address head aft = %p \n", head); | ||
for (int i = 0; i < 8; i ++) | ||
{ | ||
putchar (head[i]); | ||
} | ||
putchar ('\n'); | ||
printf ("now spare working. \n"); | ||
spare = 0x100003f27; | ||
for (int i = 0; i < 8; i ++) | ||
{ | ||
putchar (spare[i]); | ||
} | ||
putchar ('\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,41 @@ | ||
// | ||
// 11.5.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/3. | ||
// | ||
|
||
#include <stdio.h> | ||
#define SLEN 40 | ||
#define LIM 5 | ||
int main (void) | ||
{ | ||
const char * myTalents[LIM] = | ||
{ | ||
"Adding numbers swiftly", | ||
"Multiplying accurately", | ||
"Stashing data", | ||
"Following instructions to the letter", | ||
"Understanding C language" | ||
}; | ||
char yourTalents[LIM][SLEN] = | ||
{ | ||
"Walking in a strait line", | ||
"Sleeping", | ||
"Watching television", | ||
"Mailing letters", | ||
"Reading mail" | ||
}; | ||
int i; | ||
|
||
puts ("Let's compare talents. "); | ||
printf ("%-36s %-25s\n", "My talents", "Your talents"); | ||
for (i = 0; i < LIM; i ++) | ||
{ | ||
printf ("%-36s %-25s\n", myTalents[i], yourTalents[i]); | ||
} | ||
putchar ('\n'); | ||
printf ("Size of myTalents: %zd, size of yourTalents: %zd \n", sizeof (myTalents), sizeof (yourTalents)); | ||
|
||
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,19 @@ | ||
// | ||
// 11.6.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/3. | ||
// | ||
|
||
#include <stdio.h> | ||
int main (void) | ||
{ | ||
const char * mesg = "Don't be a fool"; | ||
const char * copy; | ||
|
||
printf ("© = %p\n", ©); | ||
copy = mesg; | ||
printf ("%s \n", copy); | ||
printf ("mesg = %s, &mesg = %p, value of mesg = %p\n", mesg, &mesg, mesg); | ||
printf ("cpoy = %s, © = %p, value of copy = %p\n", mesg, &mesg, mesg); | ||
} |
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,22 @@ | ||
// | ||
// 11.7.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/3. | ||
// | ||
|
||
#include <stdio.h> | ||
#define STLEN 81 | ||
int main (void) | ||
{ | ||
char words[STLEN]; | ||
|
||
puts ("Enter a string, please. "); | ||
gets (words); | ||
printf ("Your string twice: \n"); | ||
printf ("%s \n", words); | ||
puts (words); | ||
puts ("Done. "); | ||
|
||
return 0; | ||
} |
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,26 @@ | ||
// | ||
// 11.8.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/5. | ||
// | ||
|
||
#include <stdio.h> | ||
#define STLEN 14 | ||
int main (void) | ||
{ | ||
char words[STLEN]; | ||
|
||
puts ("Enter a string,please."); | ||
fgets (words, STLEN, stdin); | ||
printf ("Your string twice (puts(), then fputs()): \n"); | ||
puts (words); | ||
fputs (words, stdout); | ||
puts ("Enter another string, please."); | ||
fgets (words, STLEN, stdin); | ||
puts (words); | ||
fputs (words, stdout); | ||
puts ("Done"); | ||
|
||
return 0; | ||
} |
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,16 @@ | ||
#include <stdio.h> | ||
#define STLEN 10 | ||
//this programme will quit if enter a string which % 9 == 0 | ||
int main (void) | ||
{ | ||
char words[STLEN]; | ||
|
||
puts ("Enter strings (empty line to quit)"); | ||
while (fgets (words, STLEN, stdin) != NULL && words[0] != '\n') | ||
{ | ||
fputs (words, stdout); | ||
} | ||
puts ("Done"); | ||
|
||
return 0; | ||
} |