-
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
fe9972f
commit bc7f5ce
Showing
54 changed files
with
893 additions
and
44 deletions.
There are no files selected for viewing
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
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,37 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
char * read_things (char *st, int n); | ||
int main (void) | ||
{ | ||
char sth[20]; | ||
printf ("please enter something: \n"); | ||
printf ("%s", read_things(sth, 20)); | ||
|
||
return 0; | ||
} | ||
char * read_things (char *st, int n) | ||
{ | ||
char * ret, * f, * q, * e; | ||
ret = fgets (st, n, stdin); | ||
if (ret) | ||
{ | ||
if (strchr (ret, ' ') || strchr (ret, '\t') || strchr (ret, '\n')) | ||
{ | ||
q = strchr (ret, '\n'); | ||
f = (strchr (ret, ' ')) ? strchr (ret, ' ') : q; | ||
e = (strchr (ret, '\t')) ? strchr (ret, '\t') : q; | ||
*f = '\0'; | ||
*q = '\0'; | ||
*e = '\0'; | ||
}else | ||
{ | ||
while ((getchar() == '\n') == 0); | ||
} | ||
}else | ||
{ | ||
ret = "No result. \n"; | ||
} | ||
|
||
return ret; | ||
|
||
} |
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,61 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
char * read_things (char *st, int n); | ||
int main (void) | ||
{ | ||
char sth[90]; | ||
unsigned int j; | ||
|
||
printf ("how many charter would you like to deal? \n"); | ||
scanf ("%u", &j); | ||
getchar(); //用来处理scanf后面的回车; | ||
printf ("please enter something: \n"); | ||
printf ("%s", read_things(sth, 80)); | ||
|
||
return 0; | ||
} | ||
char * read_things (char *st, int n) | ||
{ | ||
char * red, c, *f, *e, *q; | ||
|
||
red = fgets (st, n, stdin); | ||
if (red) | ||
{ | ||
c = *red; | ||
if (c == '\n') | ||
{ | ||
*red = '\0'; | ||
return red; | ||
} | ||
if (c == '\t' || c == ' ') | ||
{ | ||
for (; (c == '\t') || (c == ' '); red ++) | ||
{ | ||
c = *red; | ||
if (c == '\n') | ||
{ | ||
*red = '\0'; | ||
return red; | ||
} | ||
} | ||
red --; | ||
} | ||
if (strchr (red, ' ') || strchr (red, '\t') || strchr (red, '\n')) | ||
{ | ||
q = strchr (red, '\n'); | ||
f = (strchr (red, ' ')) ? strchr (red, ' ') : q; | ||
e = (strchr (red, '\t')) ? strchr (red, '\t') : q; | ||
*q = '\0'; | ||
*f = '\0'; | ||
*e = '\0'; | ||
}else | ||
{ | ||
while (getchar() != '\n'); | ||
} | ||
}else | ||
{ | ||
red = "No result. \n"; | ||
} | ||
|
||
return red; | ||
} |
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,58 @@ | ||
#include "s_gets.h" | ||
const char * strchar (const char * st, char ch); | ||
int main (void) | ||
{ | ||
char str[80], ch; | ||
|
||
printf ("please enter a sentence: \n"); | ||
s_gets (str, 80); | ||
printf ("please enter a charter: \n"); | ||
ch = getchar (); | ||
if (ch != '\n') | ||
{ | ||
getchar(); | ||
}else; | ||
while (*str != '\0') | ||
{ | ||
if (strchar (str, ch)) | ||
{ | ||
printf ("%c is in %s! \n", ch, str); | ||
}else | ||
{ | ||
printf ("there is no %c in %s! \n", ch, str); | ||
} | ||
printf ("please enter another sentence: \n"); | ||
s_gets (str, 80); | ||
printf ("please enter a charter: \n"); | ||
ch = getchar (); | ||
if (ch != '\n') | ||
{ | ||
getchar(); | ||
}else; | ||
} | ||
printf ("thank you!\n"); | ||
|
||
return 0; | ||
} | ||
const char * strchar (const char * st, char ch) | ||
{ | ||
const char * temp; | ||
int p = 1; | ||
|
||
for (int j = 0; j < strlen (st); j ++) | ||
{ | ||
if (ch == st[j]) | ||
{ | ||
p = 0; | ||
break; | ||
}else; | ||
} | ||
if (p == 0) | ||
{ | ||
temp = st; | ||
return temp; | ||
}else | ||
{ | ||
return NULL; | ||
} | ||
} |
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,55 @@ | ||
#include "s_gets.h" | ||
int is_within (const char * st, char ch); | ||
int main (void) | ||
{ | ||
char ch, str[80]; | ||
|
||
printf ("please enter a sentence: \n"); | ||
s_gets (str, 80); | ||
printf ("please enter a charter: \n"); | ||
ch = getchar (); | ||
if (ch != '\n') | ||
{ | ||
getchar(); | ||
}else; | ||
while (*str) | ||
{ | ||
if (is_within (str, ch)) | ||
{ | ||
printf ("%c appears in %s for %d times! \n", ch, str, is_within(str, ch)); | ||
}else | ||
{ | ||
printf ("there is no %c in %s! \n", ch, str); | ||
} | ||
printf ("please enter another sentence: \n"); | ||
s_gets (str, 80); | ||
printf ("please enter a charter: \n"); | ||
ch = getchar (); | ||
if (ch != '\n') | ||
{ | ||
getchar(); | ||
}else; | ||
} | ||
printf ("thank you!\n"); | ||
|
||
return 0; | ||
} | ||
int is_within (const char * st, char ch) | ||
{ | ||
int p = 0; | ||
|
||
for (int j = 0; j < strlen (st); j ++) | ||
{ | ||
if (ch == st[j]) | ||
{ | ||
p ++; | ||
}else; | ||
} | ||
if (p != 0) | ||
{ | ||
return p; | ||
}else | ||
{ | ||
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,44 @@ | ||
#include "s_gets.h" | ||
#define SHIT 80 | ||
char * mystrncpy (char * st1, const char * st2, int n); | ||
int main (void) | ||
{ | ||
char str1[SHIT], str2[SHIT]; | ||
int q; | ||
|
||
printf ("please keep enter two sentences, the second one will bite the tail of the first one. \n"); | ||
while (1) | ||
{ | ||
printf ("now enter the first one: \n"); | ||
s_gets (str1, SHIT); | ||
printf ("now enter the second one: \n"); | ||
s_gets (str2, SHIT); | ||
if (!*str1 || !*str2) | ||
{ | ||
break; | ||
}else | ||
{ | ||
printf ("how many charater would you like to paste: \n"); | ||
scanf ("%d", &q); | ||
getchar(); | ||
printf ("%s\n", mystrncpy(str1, str2, q)); | ||
printf ("please enter next two sentences. \n"); | ||
} | ||
} | ||
printf ("thank you\n"); | ||
|
||
return 0; | ||
} | ||
char * mystrncpy (char * st1, const char * st2, int n) | ||
{ | ||
int j = strlen (st1); | ||
int p = 0; | ||
|
||
for (; j < SHIT && p < n && st2[p]; j ++, p ++) | ||
{ | ||
st1[j] = st2[p]; | ||
} | ||
st1 [j] = '\0'; | ||
|
||
return st1; | ||
} |
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,55 @@ | ||
#include "s_gets.h" | ||
#define LONG 80 | ||
char * string_in (char * st1, char * st2); | ||
int main (void) | ||
{ | ||
char str1[LONG], str2[LONG]; | ||
|
||
printf ("this program is checking if the second string is include by the first one. \n"); | ||
while (1) | ||
{ | ||
printf ("now enter the first one: \n"); | ||
s_gets (str1, LONG); | ||
printf ("now enter the second one: \n"); | ||
s_gets (str2, LONG); | ||
if (!*str1 || !*str2) | ||
{ | ||
break; | ||
}else | ||
{ | ||
char *result = string_in(str1, str2); | ||
if (result) | ||
{ | ||
printf("'%s' is in '%s' at position %ld.\n", str2, str1, result - str1 + 1); | ||
} | ||
else | ||
{ | ||
printf("'%s' is not found in '%s'.\n", str2, str1); | ||
} | ||
printf("Please enter next two strings. \n"); | ||
} | ||
} | ||
printf ("thank you\n"); | ||
|
||
return 0; | ||
} | ||
char * string_in (char * st1, char * st2) | ||
{ | ||
int j, p, leng1 = strlen (st1), leng2 = strlen (st2); | ||
|
||
for (j = 0; j < leng1 - leng2 + 1; j ++) | ||
{ | ||
for (p = 0; p < strlen (st2); p ++) | ||
{ | ||
if (st1[j + p] != st2[p]) | ||
{ | ||
break; | ||
}else; | ||
} | ||
if (p == leng2) | ||
{ | ||
return st1 + j; | ||
}else; | ||
} | ||
return NULL; | ||
} |
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,38 @@ | ||
#include "s_gets.h" | ||
#define LONG 80 | ||
char * converce (char * str, char * rts); | ||
int main (void) | ||
{ | ||
char str1[LONG]; | ||
|
||
printf ("this program converses sentences. \n"); | ||
printf("now enter the sentence: \n"); | ||
while (1) | ||
{ | ||
s_gets(str1, LONG); | ||
if (!*str1) | ||
{ | ||
break; | ||
}else | ||
{ | ||
char rts[strlen (str1) + 1]; | ||
printf ("%s\n", converce (str1, rts)); | ||
} | ||
printf ("now enter another sentence: \n"); | ||
} | ||
printf ("thank you\n"); | ||
|
||
return 0; | ||
} | ||
char * converce (char * str, char * rts) | ||
{ | ||
unsigned long int j = 0, p = strlen (str); | ||
|
||
for (; j <= p; j ++) | ||
{ | ||
rts[j] = str[p - j - 1]; | ||
} | ||
rts[p] = '\0'; | ||
|
||
return rts; | ||
} |
Oops, something went wrong.