Skip to content

Commit

Permalink
update 2.10, happy lunar new year
Browse files Browse the repository at this point in the history
  • Loading branch information
TGSpock123 committed Feb 10, 2024
1 parent fe9972f commit bc7f5ce
Show file tree
Hide file tree
Showing 54 changed files with 893 additions and 44 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified 11/.DS_Store
Binary file not shown.
Binary file added 11/11/.11.47.c.swp
Binary file not shown.
Binary file modified 11/11/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion 11/11/11.29.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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);
Expand Down
37 changes: 37 additions & 0 deletions 11/11/11.35.c
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;

}
61 changes: 61 additions & 0 deletions 11/11/11.36.c
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;
}
58 changes: 58 additions & 0 deletions 11/11/11.37.c
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;
}
}
55 changes: 55 additions & 0 deletions 11/11/11.38.c
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;
}
}
44 changes: 44 additions & 0 deletions 11/11/11.39.c
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;
}
55 changes: 55 additions & 0 deletions 11/11/11.40.c
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;
}
38 changes: 38 additions & 0 deletions 11/11/11.41.c
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;
}
Loading

0 comments on commit bc7f5ce

Please sign in to comment.