Skip to content

Commit

Permalink
11.9 update
Browse files Browse the repository at this point in the history
  • Loading branch information
TGSpock123 committed Jan 9, 2024
1 parent 2a97ee2 commit b370688
Show file tree
Hide file tree
Showing 23 changed files with 350 additions and 4 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file not shown.
Binary file modified 11/.DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions 11/11.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
objects = {

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

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -23,8 +23,8 @@
/* 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; };
7AF5A9D82B3958EC00A0A48F /* 11.1.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = 11.1.c; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -57,7 +57,7 @@
7AF5A9D02B39588F00A0A48F /* 11 */ = {
isa = PBXGroup;
children = (
7AF5A9D82B3958EC00A0A48F /* 11.1.c */,
7AEAEA522B4CE61B00FF61E5 /* 11.15.c */,
);
path = 11;
sourceTree = "<group>";
Expand Down Expand Up @@ -119,7 +119,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7AF5A9D92B3958EC00A0A48F /* 11.1.c in Sources */,
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.
Binary file added 11/11/11.10
Binary file not shown.
29 changes: 29 additions & 0 deletions 11/11/11.10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
int main (void)
{
char words[10];
int i = 0;

puts ("Enter strings(empty line to quit):");
while (fgets (words, 10, stdin) != NULL && words[0] != '\n')
{
while (words[i] != '\n' && words[i] != '\0')
{
i ++;
}
if (words[i] == '\n')
{
words[i] = '\0';
}else
{
while (getchar() != '\n')
{
continue;
}
}
puts (words);
}
puts ("done");

return 0;
}
19 changes: 19 additions & 0 deletions 11/11/11.11.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// 11.11.c
// 11
//
// Created by T G Spock on 2024/1/8.
//

#include <stdio.h>
int main (void)
{
char name1[11], name2[11];
int count;

printf ("Please enter 2 names.\n");
count = scanf ("%5s %10s", name1, name2);
printf ("I read %d names %s and %s.\n", count, name1, name2);

return 0;
}
23 changes: 23 additions & 0 deletions 11/11/11.12.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// 11.12.c
// 11
//
// Created by T G Spock on 2024/1/8.
//

#include <stdio.h>
#define DEF "I am a #defined string."
int main (void)
{
char str1[80] = "An array was initialized to me. ";
const char *str2 = "A pointer was initialized to me. ";

puts ("I am an argument to puts(). ");
puts (DEF);
puts (str1);
puts (str2);
puts (&str1[5]);
puts (str2 +4);

return 0;
}
19 changes: 19 additions & 0 deletions 11/11/11.13.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// 11.13.c
// 11
//
// Created by T G Spock on 2024/1/8.
//

#include <stdio.h>
int main (void)
{
char side_a[] = "Side A";
char dont[] = {'W', 'O', 'W', '!'};
char side_b[] = "Side B";

printf ("side_a = %p, dont = %p, side_b[] = %p\n", side_a, dont, side_b);
puts (dont);

return 0;
}
28 changes: 28 additions & 0 deletions 11/11/11.14.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// 11.14.c
// 11
//
// Created by T G Spock on 2024/1/8.
//

#include <stdio.h>
int main (void)
{
char line[8];
int i;

printf ("Now puts() speaking: \n");
while (gets (line) && line[0] != EOF)
{
i = 0;
puts (line);
}
printf ("Now fputs() speaking: \n");
while (fgets (line, 8, stdin) && line[0] != '\n')
{
i = 0;
fputs (line, stdout);
}

return 0;
}
8 changes: 8 additions & 0 deletions 11/11/11.15.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// 11.15.c
// 11
//
// Created by T G Spock on 2024/1/9.
//

#include <stdio.h>
14 changes: 14 additions & 0 deletions 11/11/11.2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// 11.2.c
// 11
//
// Created by T G Spock on 2024/1/2.
//

#include <stdio.h>
int main (void)
{
printf ("%s, %p, %c\n", "We", "are", *"space farers");

return 0;
}
22 changes: 22 additions & 0 deletions 11/11/11.3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// 11.3.c
// 11
//
// Created by T G Spock on 2024/1/2.
//

#define MSG "I'm special"
#include <stdio.h>
int main (void)
{
char ar[] = MSG;
const char * pt = MSG;

printf ("address of \"I'm special\": %p \n", "I'm special");
printf (" address ar: %p \n", ar);
printf (" address pt: %p \n", pt);
printf (" address of MSG: %p \n", MSG);
printf ("address of \"I'm special\": %p \n", "I'm special");

return 0;
}
60 changes: 60 additions & 0 deletions 11/11/11.4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// 11.4.c
// 11
//
// Created by T G Spock on 2024/1/2.
//

#include <stdio.h>
int main (void)
{
char heart[] = "I love A";
const char * head = "I love B";
const char * spare;

printf ("address heart = %p\n", heart);
printf ("address head = %p\n", head);
printf ("address spare = %p\n", spare);
for (int i = 0; i < 8; i ++)
{
putchar (heart[i]);
}
putchar ('\n');
for (int i = 0; i < 8; i ++)
{
putchar (head[i]);
}
putchar ('\n');
for (int i = 0; i < 8; i ++)
{
putchar (*(heart + i));
}
putchar ('\n');
for (int i = 0; i < 8; i ++)
{
putchar (*(head + i));
}
putchar ('\n');
while (*(head) != '\0')
{
putchar (*(head++));
}
putchar ('\n');
printf ("address head b4 = %p \n", head);
head = heart;
printf ("address head aft = %p \n", head);
for (int i = 0; i < 8; i ++)
{
putchar (head[i]);
}
putchar ('\n');
printf ("now spare working. \n");
spare = 0x100003f27;
for (int i = 0; i < 8; i ++)
{
putchar (spare[i]);
}
putchar ('\n');

return 0;
}
41 changes: 41 additions & 0 deletions 11/11/11.5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// 11.5.c
// 11
//
// Created by T G Spock on 2024/1/3.
//

#include <stdio.h>
#define SLEN 40
#define LIM 5
int main (void)
{
const char * myTalents[LIM] =
{
"Adding numbers swiftly",
"Multiplying accurately",
"Stashing data",
"Following instructions to the letter",
"Understanding C language"
};
char yourTalents[LIM][SLEN] =
{
"Walking in a strait line",
"Sleeping",
"Watching television",
"Mailing letters",
"Reading mail"
};
int i;

puts ("Let's compare talents. ");
printf ("%-36s %-25s\n", "My talents", "Your talents");
for (i = 0; i < LIM; i ++)
{
printf ("%-36s %-25s\n", myTalents[i], yourTalents[i]);
}
putchar ('\n');
printf ("Size of myTalents: %zd, size of yourTalents: %zd \n", sizeof (myTalents), sizeof (yourTalents));

return 0;
}
19 changes: 19 additions & 0 deletions 11/11/11.6.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// 11.6.c
// 11
//
// Created by T G Spock on 2024/1/3.
//

#include <stdio.h>
int main (void)
{
const char * mesg = "Don't be a fool";
const char * copy;

printf ("&copy = %p\n", &copy);
copy = mesg;
printf ("%s \n", copy);
printf ("mesg = %s, &mesg = %p, value of mesg = %p\n", mesg, &mesg, mesg);
printf ("cpoy = %s, &copy = %p, value of copy = %p\n", mesg, &mesg, mesg);
}
22 changes: 22 additions & 0 deletions 11/11/11.7.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// 11.7.c
// 11
//
// Created by T G Spock on 2024/1/3.
//

#include <stdio.h>
#define STLEN 81
int main (void)
{
char words[STLEN];

puts ("Enter a string, please. ");
gets (words);
printf ("Your string twice: \n");
printf ("%s \n", words);
puts (words);
puts ("Done. ");

return 0;
}
Binary file added 11/11/11.8
Binary file not shown.
26 changes: 26 additions & 0 deletions 11/11/11.8.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// 11.8.c
// 11
//
// Created by T G Spock on 2024/1/5.
//

#include <stdio.h>
#define STLEN 14
int main (void)
{
char words[STLEN];

puts ("Enter a string,please.");
fgets (words, STLEN, stdin);
printf ("Your string twice (puts(), then fputs()): \n");
puts (words);
fputs (words, stdout);
puts ("Enter another string, please.");
fgets (words, STLEN, stdin);
puts (words);
fputs (words, stdout);
puts ("Done");

return 0;
}
Binary file added 11/11/11.9
Binary file not shown.
16 changes: 16 additions & 0 deletions 11/11/11.9.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>
#define STLEN 10
//this programme will quit if enter a string which % 9 == 0
int main (void)
{
char words[STLEN];

puts ("Enter strings (empty line to quit)");
while (fgets (words, STLEN, stdin) != NULL && words[0] != '\n')
{
fputs (words, stdout);
}
puts ("Done");

return 0;
}

0 comments on commit b370688

Please sign in to comment.