-
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
b370688
commit 23594cb
Showing
32 changed files
with
337 additions
and
28 deletions.
There are no files selected for viewing
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
+2.9 KB
(110%)
...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
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,12 @@ | ||
// | ||
// 11.15_16.h | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/9. | ||
// | ||
|
||
#ifndef _1_15_16_h | ||
#define _1_15_16_h | ||
void put1 (const char * string); | ||
int put2 (const char * string); | ||
#endif /* _1_15_16_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,31 @@ | ||
// | ||
// 11.16.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/9. | ||
// | ||
|
||
#include <stdio.h> | ||
#include "11.15_16.h" | ||
void put1 (const char * string) | ||
{ | ||
while (*string) | ||
{ | ||
putchar (*string); | ||
string ++; | ||
} | ||
} | ||
int put2 (const char * string) | ||
{ | ||
int i = 0; | ||
|
||
while (*string) | ||
{ | ||
putchar (*string); | ||
string ++; | ||
i ++; | ||
} | ||
putchar ('\n'); | ||
|
||
return i; | ||
} |
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 @@ | ||
// | ||
// 11.17.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/9. | ||
// | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
void fit (char * string, unsigned int size); | ||
int main (void) | ||
{ | ||
char mesg[] = "Things should be as simple as possible but not simpler."; | ||
|
||
puts (mesg); | ||
fit (mesg, 38); | ||
puts (mesg); | ||
puts ("Let's look at some more of the string."); | ||
puts (mesg + 39); | ||
|
||
return 0; | ||
} | ||
void fit (char * string, unsigned int size) | ||
{ | ||
if (strlen (string) > size) | ||
{ | ||
string[size] = '\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,28 @@ | ||
// | ||
// 11.18.c | ||
// 11 | ||
// | ||
// Created by T G Spock on 2024/1/9. | ||
// | ||
|
||
#define SIZE 80 | ||
#include "s_gets.h" | ||
int main (void) | ||
{ | ||
char flower[SIZE]; | ||
char addon[] = "s smell like old shoes. "; | ||
|
||
puts ("What is your favorate flower?"); | ||
if (s_gets(flower, SIZE)) | ||
{ | ||
strcat (flower, addon); | ||
puts (flower); | ||
puts (addon); | ||
}else | ||
{ | ||
puts ("End of file encourtered!"); | ||
} | ||
puts ("bye"); | ||
|
||
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,25 @@ | ||
#include "s_gets.h" | ||
#define SIZE 30 | ||
#define BUGSIZE 13 | ||
int main (void) | ||
{ | ||
char flower[SIZE]; | ||
char addon[] = "s smell like old shoes."; | ||
char bug[BUGSIZE]; | ||
int available; | ||
|
||
puts ("What's your favorite flower? "); | ||
s_gets (flower, SIZE); | ||
if ((strlen (addon) + strlen (flower) + 1) <= SIZE) | ||
{ | ||
strcat (flower, addon); | ||
} | ||
puts (flower); | ||
puts ("What's your favorite bug? "); | ||
s_gets (bug, BUGSIZE); | ||
available = BUGSIZE - strlen (bug) - 1;// 句末要有\0 | ||
strncat (bug, addon, available); | ||
puts (bug); | ||
|
||
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,84 @@ | ||
#include "s_gets.h" | ||
#define ANSWER "Grant" | ||
#define SIZE 40 | ||
int cmpa (char * ar1, char * ar2);// 前面是原始数组 | ||
int main (void) | ||
{ | ||
char try[SIZE]; | ||
int i = 1; | ||
|
||
puts ("Who is buried in Grant's tomb? "); | ||
do | ||
{ | ||
s_gets(try, SIZE); | ||
if (cmpa (ANSWER, try)) | ||
{ | ||
(i == 3) ? puts ("No, that's wrong. "): puts ("No, that's wrong. Try again. "); | ||
}else { | ||
puts("That's right!"); | ||
break; | ||
} | ||
i ++; | ||
} | ||
while (i <= 3); | ||
|
||
return 0; | ||
} | ||
int cmpa (char * ar1, char * ar2) | ||
{ | ||
int p = 0; | ||
|
||
for (int i = 0; i < strlen (ar1); i++) | ||
{ | ||
p += ar1[i]; | ||
} | ||
for (int i = 0; i < strlen (ar2); i++) | ||
{ | ||
p -= ar2[i]; | ||
} | ||
|
||
return p; | ||
} | ||
|
||
/* show off from my friend. | ||
#include <stdio.h> | ||
#include <math.h> | ||
int main() | ||
{ | ||
int c; | ||
printf("please put in a number:\n"); | ||
scanf("%d", &c); | ||
if(c<2) | ||
{ | ||
printf("error"); | ||
} | ||
else | ||
{ | ||
int a[c]; | ||
for(int i = 0; i < c; i ++) | ||
{ | ||
a[i] = i + 2; | ||
} | ||
for (int j=2;j<(sqrt(c)+1);j++) | ||
{ | ||
for(int i=1 ;i < (sizeof (a))/(sizeof(a[0])); i++) | ||
{ | ||
if( a[i] != 0 & a[i] != j & a[i] % j == 0) | ||
{ | ||
a[i] = 0; | ||
} | ||
} | ||
} | ||
for(int i=0;i < (sizeof (a))/(sizeof(a[0])) ;i++) { | ||
if (a[i] != 0) | ||
printf("%d\t", a[i]); | ||
} | ||
} | ||
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,25 @@ | ||
#include "s_gets.h" | ||
#define ANSWER "Grant" | ||
#define SIZE 40 | ||
int main (void) | ||
{ | ||
char try[SIZE]; | ||
int i = 1; | ||
|
||
puts ("Who is buried in Grant's tomb? "); | ||
do | ||
{ | ||
s_gets(try, SIZE); | ||
if (strcmp (ANSWER, try)) | ||
{ | ||
(i == 3) ? puts ("No, that's wrong. "): puts ("No, that's wrong. Try again. "); | ||
}else { | ||
puts("That's right!"); | ||
break; | ||
} | ||
i ++; | ||
} | ||
while (i <= 3); | ||
|
||
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,13 @@ | ||
#include "s_gets.h" | ||
int main (void) | ||
{ | ||
char ch[20], ch2[20]; | ||
|
||
printf ("Please enter an array. \n"); | ||
s_gets (ch, 20); | ||
printf ("Please enter another array. \n"); | ||
s_gets (ch2, 20); | ||
printf ("strcmp (\"%s\" and \"%s\") is %d. \n", ch, ch2, strcmp (ch, ch2)); | ||
|
||
return 0; | ||
} |
Empty file.
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,27 @@ | ||
#include "s_gets.h" | ||
char * s_gets (char *st, int n) | ||
{ | ||
char * ret_val; | ||
int i = 0; | ||
|
||
ret_val = fgets(st, n, stdin); | ||
if (ret_val) | ||
{ | ||
while ((st[i] != '\n') && (st[i])) | ||
{ | ||
i ++; | ||
} | ||
if (st[i] == '\n') | ||
{ | ||
st[i] = '\0'; | ||
}else | ||
{ | ||
while ((getchar() == '\n') == 0) | ||
{ | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
return ret_val; | ||
} |
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,3 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
char * s_gets (char *st, int n); |
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
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
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
Oops, something went wrong.