Skip to content

Commit

Permalink
daily upload 1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
TGSpock123 committed Jan 17, 2024
1 parent b370688 commit 23594cb
Show file tree
Hide file tree
Showing 32 changed files with 337 additions and 28 deletions.
7 changes: 0 additions & 7 deletions 11/11.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
objectVersion = 56;
objects = {

/* Begin PBXBuildFile section */
7AEAEA532B4CE61B00FF61E5 /* 11.15.c in Sources */ = {isa = PBXBuildFile; fileRef = 7AEAEA522B4CE61B00FF61E5 /* 11.15.c */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
7AF5A9CC2B39588F00A0A48F /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
Expand All @@ -23,7 +19,6 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
7AEAEA522B4CE61B00FF61E5 /* 11.15.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = 11.15.c; sourceTree = "<group>"; };
7AF5A9CE2B39588F00A0A48F /* 11 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = 11; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -57,7 +52,6 @@
7AF5A9D02B39588F00A0A48F /* 11 */ = {
isa = PBXGroup;
children = (
7AEAEA522B4CE61B00FF61E5 /* 11.15.c */,
);
path = 11;
sourceTree = "<group>";
Expand Down Expand Up @@ -119,7 +113,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7AEAEA532B4CE61B00FF61E5 /* 11.15.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
Binary file modified 11/11/.DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions 11/11/11.15.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@
//

#include <stdio.h>
#include "11.15_16.h"
int main (void)
{
put1 ("if I'd as much money");
put1 (" as I could spend, \n");
printf ("I count %d charaters.\n", put2("I never would cry old chairs to mend."));

return 0;
}
12 changes: 12 additions & 0 deletions 11/11/11.15_16.h
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 */
31 changes: 31 additions & 0 deletions 11/11/11.16.c
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;
}
29 changes: 29 additions & 0 deletions 11/11/11.17.c
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 added 11/11/11.18
Binary file not shown.
28 changes: 28 additions & 0 deletions 11/11/11.18.c
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;
}
25 changes: 25 additions & 0 deletions 11/11/11.19.c
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;
}
84 changes: 84 additions & 0 deletions 11/11/11.20.c
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;
}
*/
25 changes: 25 additions & 0 deletions 11/11/11.21.c
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;
}
13 changes: 13 additions & 0 deletions 11/11/11.22.c
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 added 11/11/11.23.c
Empty file.
27 changes: 27 additions & 0 deletions 11/11/s_gets.c
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;
}
3 changes: 3 additions & 0 deletions 11/11/s_gets.h
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);
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ set(CMAKE_CXX_STANDARD 14)
include_directories(9)

add_executable(C_primer
10_plus_2/10_plus_2/10.30.c
11/11/11.22.c 11/11/s_gets.c
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{
"directoryIndex" : 0,
"id" : "C_primer::@6890427a1f51a3e7e1df",
"jsonFile" : "target-C_primer-Debug-767772fb1b3578ca477a.json",
"jsonFile" : "target-C_primer-Debug-0a97314528f9f09bd539.json",
"name" : "C_primer",
"projectIndex" : 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"objects" :
[
{
"jsonFile" : "codemodel-v2-0eebd294b99a0194708d.json",
"jsonFile" : "codemodel-v2-5617b905eb5271d10553.json",
"kind" : "codemodel",
"version" :
{
Expand Down Expand Up @@ -86,7 +86,7 @@
},
"codemodel-v2" :
{
"jsonFile" : "codemodel-v2-0eebd294b99a0194708d.json",
"jsonFile" : "codemodel-v2-5617b905eb5271d10553.json",
"kind" : "codemodel",
"version" :
{
Expand Down
Loading

0 comments on commit 23594cb

Please sign in to comment.