-
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
23594cb
commit 9186b78
Showing
32 changed files
with
461 additions
and
49 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.
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,19 @@ | ||
#include "s_gets.h" | ||
#define SIZE 80 | ||
#define LIM 10 | ||
#define STOP "quit" | ||
int main (void) | ||
{ | ||
char input[LIM][SIZE]; | ||
int ct = 0; | ||
|
||
printf ("Enter up to %d lines (type quit to quit): \n", LIM); | ||
while (ct < LIM && s_gets (input[ct], SIZE) != NULL && | ||
strcmp (input[ct], STOP) != 0 && input[ct][0] != '\0') | ||
{ | ||
ct ++; | ||
} | ||
printf ("%d strings entered. \n", ct); | ||
|
||
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,29 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#define LISTSIZE 6 | ||
int main (void) | ||
{ | ||
const char * list[LISTSIZE] = | ||
{ | ||
"astronomy", | ||
"astounding", | ||
"astrophysics", | ||
"ostracize", | ||
"asterism", | ||
"astrophobia" | ||
}; | ||
int count = 0; | ||
int i; | ||
|
||
for (i = 0; i < LISTSIZE; i++) | ||
{ | ||
if (strncmp (list[i], "astr", 4) == 0) | ||
{ | ||
printf ("Found: %s.\n", list[i]); | ||
count ++; | ||
} | ||
} | ||
printf ("The list contained %d words beginning with astr. \n", count); | ||
|
||
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,30 @@ | ||
#include "s_gets.h" | ||
#define SIZE 40 | ||
#define LIM 5 | ||
int main (void) | ||
{ | ||
char qwords[LIM][SIZE]; | ||
char temp[SIZE]; | ||
int i = 0; | ||
|
||
printf ("Enter %d words beginning with q: \n", LIM); | ||
while (i < LIM && s_gets(temp, SIZE)) | ||
{ | ||
if (temp[0] != 'q') | ||
{ | ||
printf ("%s doesn't begin with q! \n", temp); | ||
}else | ||
{ | ||
strcpy (qwords[i], temp); | ||
i ++; | ||
} | ||
} | ||
puts ("\nHere are the words accepted: "); | ||
for (i = 0; i < LIM; i ++) | ||
{ | ||
puts (qwords[i]); | ||
} | ||
|
||
return 0; | ||
} | ||
//后面是被复制字符串, 把后面的放进前面的, 参考 mov ax, 4 |
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> | ||
#include <string.h> | ||
#define WORD "beast" | ||
#define SIZE 40 | ||
int main (void) | ||
{ | ||
const char * orig = WORD; | ||
char copy[SIZE] = "Be the best you can be."; | ||
char * ps; | ||
|
||
puts (copy); | ||
ps = strcpy (copy + 7, orig); | ||
puts (copy); | ||
|
||
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,31 @@ | ||
#include "s_gets.h" | ||
#define SIZE 40 | ||
#define TARGETSIZE 7 | ||
#define LIM 5 | ||
int main (void) | ||
{ | ||
char qwords[LIM][TARGETSIZE]; | ||
char temp[SIZE]; | ||
int i = 0; | ||
|
||
printf ("Enter %d words beginning with q: \n", LIM); | ||
while (i < LIM && s_gets(temp, SIZE)) | ||
{ | ||
if (temp[0] != 'q') | ||
{ | ||
printf ("%s doesn't begging with 'q'! \n", temp); | ||
}else | ||
{ | ||
strncpy (qwords[i], temp, TARGETSIZE - 1); | ||
qwords[i][TARGETSIZE - 1] = '\0'; | ||
i ++; | ||
} | ||
} | ||
puts ("Here are the words accepted:"); | ||
for (i = 0; i < LIM; i ++) | ||
{ | ||
puts (qwords[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,20 @@ | ||
#include "s_gets.h" | ||
#define MAX 20 | ||
int main (void) | ||
{ | ||
char first[MAX]; | ||
char last[MAX]; | ||
char formal[2 * MAX + 10]; | ||
double prize; | ||
|
||
puts ("Enter your first name: "); | ||
s_gets (first, MAX); | ||
puts ("Enter your last name: "); | ||
s_gets (last, MAX); | ||
puts ("Enter your prize money: "); | ||
scanf ("%lf", &prize); | ||
sprintf (formal, "%s %-19s: $%6.2f\n",first, last, prize); | ||
puts (formal); | ||
|
||
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,114 @@ | ||
//test | ||
#include "s_gets.h" | ||
int main (void) | ||
{ | ||
char ch1[40], ch2[40], q, *qwe; | ||
int i = 5; | ||
|
||
printf ("please enter ch1, strcpy wil make ch2: \n"); | ||
s_gets (ch1, 40); | ||
printf ("1. %s\n", ch1); | ||
strcpy (ch2, ch1); | ||
printf ("1. %s\n", ch2); | ||
|
||
printf ("please enter ch1, strncpy wil make ch2: \n"); | ||
s_gets (ch1, 40); | ||
printf ("2. %s\n",ch1); | ||
strncpy (ch2, ch1, i); | ||
ch2[i] = '\0'; | ||
printf ("2. %s\n", ch2); | ||
|
||
printf ("this test is for strcat, please enter ch1: \n"); | ||
s_gets (ch1, 40); | ||
printf ("please enter ch2: \n"); | ||
s_gets (ch2, 40); | ||
strcat (ch1, ch2); | ||
printf ("3. %s\n", ch1); | ||
|
||
printf ("this is for strncat, please enter ch1: \n"); | ||
s_gets (ch1, 40); | ||
printf ("please enter ch2: \n"); | ||
s_gets (ch2, 40); | ||
strncat (ch1, ch2, 40 - 1 - strlen(ch1)); | ||
printf ("4. %s\n", ch1); | ||
|
||
printf ("this test is for strcmp, please enter ch1: \n"); | ||
s_gets (ch1, 40); | ||
printf ("please enter ch2: \n"); | ||
s_gets (ch2, 40); | ||
printf ("5. %d\n", strcmp (ch1, ch2)); | ||
|
||
printf ("this is for strncmp, please enter ch1: \n"); | ||
s_gets (ch1, 40); | ||
printf ("please enter ch2: \n"); | ||
s_gets (ch2, 40); | ||
printf ("6. %d\n", strncmp (ch1, ch2, i)); | ||
|
||
//书上这段错了, 具体看示例代码 | ||
printf ("this test is for strchr, please enter ch1: \n"); | ||
s_gets (ch1, 40); | ||
printf ("please enter a charater: \n"); | ||
q = getchar(); | ||
getchar(); | ||
if (!strchr (ch1, q)) | ||
{ | ||
printf ("7. there is no %c in ch1: %s\n", q, ch1); | ||
}else | ||
{ | ||
qwe = strchr (ch1, q); | ||
printf ("7. %c is in ch1: %s, after %c is %s\n", q, ch1, q, qwe + 1); | ||
} | ||
|
||
//这段也错了 | ||
printf ("this test is for strpbrk, please enter ch1: \n"); | ||
s_gets (ch1, 40); | ||
printf ("please enter ch2: \n"); | ||
s_gets (ch2, 40); | ||
if (!strpbrk (ch1, ch2)) | ||
{ | ||
printf ("8. there is no element of ch2: %s in ch1: %s\n", ch2, ch1); | ||
}else | ||
{ | ||
qwe = strpbrk (ch1, ch2); | ||
printf ("8. there is at least one element" | ||
"of ch2: %s is in ch1: %s \nafter the first match is %s\n", ch2, ch1, qwe + 1); | ||
while (!strpbrk (qwe + 1, ch2)) | ||
{ | ||
qwe = strpbrk (qwe + 1, ch2); | ||
printf ("after next match is %s\n", qwe + 1); | ||
} | ||
} | ||
|
||
printf ("this test is for strrchr, please enter ch1: \n"); | ||
s_gets (ch1, 40); | ||
printf ("please enter a charater: \n"); | ||
q = getchar(); | ||
getchar(); | ||
if (!strrchr (ch1, q)) | ||
{ | ||
printf ("9. there is no %c in ch1: %s\n", q, ch1); | ||
}else | ||
{ | ||
qwe = strrchr (ch1, q); | ||
printf ("9. %c is in ch1: %s, after %c' last match is %s\n", q, ch1, q, qwe + 1); | ||
} | ||
|
||
printf ("this test is for strstr, please enter ch1: \n"); | ||
s_gets (ch1, 40); | ||
printf ("please enter ch2: \n"); | ||
s_gets (ch2, 40); | ||
if (!strstr (ch1, ch2)) | ||
{ | ||
printf ("10. ch2: %s is not in ch1: %s\n", ch2, ch1); | ||
}else | ||
{ | ||
qwe = strstr (ch1, ch2); | ||
printf ("10. ch2: %s is in ch1: %s, after ch2 is %s\n", ch2, ch1, qwe + strlen(ch2)); | ||
} | ||
|
||
printf ("this test is for strlen, please enter ch1: \n"); | ||
s_gets (ch1, 40); | ||
printf ("the length of ch1: %s is %lu\n", ch1, strlen (ch1)); | ||
|
||
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,47 @@ | ||
#include "s_gets.h" | ||
#define SIZE 81 | ||
#define LIM 20 | ||
#define HALT "" | ||
|
||
void stsrt (char *strings[], int num) | ||
{ | ||
char *temp; | ||
int top, seek; | ||
|
||
for (top = 0; top < num - 1; top ++) | ||
{ | ||
for (seek = top + 1; seek < num; seek ++) | ||
{ | ||
if (strcmp (strings[top], strings[seek]) > 0) | ||
{ | ||
temp = strings[top]; | ||
strings[top] = strings[seek]; | ||
strings[seek] = temp; | ||
} | ||
} | ||
} | ||
} | ||
|
||
int main (void) | ||
{ | ||
char input[LIM][SIZE]; | ||
char *ptstr[LIM]; | ||
int ct = 0; | ||
int k; | ||
|
||
printf ("Input up to %d lines, and I will sort em. \n", LIM); | ||
printf ("Press enter in an empty line to quit. \n"); | ||
while (ct < LIM && s_gets(input[ct], SIZE) && input[ct][0]) | ||
{ | ||
ptstr[ct] = input[ct]; | ||
ct ++; | ||
} | ||
stsrt (ptstr, ct); | ||
puts ("\nHere's the sort list: \n"); | ||
for (k = 0; k < ct; k ++) | ||
{ | ||
puts (ptstr[k]); | ||
} | ||
|
||
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
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.