init commit

This commit is contained in:
2016-07-21 10:22:47 -07:00
commit cb4eb030bd
55 changed files with 1209 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
CFLAGS=-Wall -g
clean:
rm -f ex1

BIN
learncthehardway/3/ex3 Executable file

Binary file not shown.

12
learncthehardway/3/ex3.c Normal file
View File

@@ -0,0 +1,12 @@
#include <stdio.h>
int main()
{
int age = 10;
int height = 72;
printf("I am %d years old.\n", age );
printf("I am %d inches tall.\n", height);
return 0;
}

View File

@@ -0,0 +1,4 @@
CFLAGS=-Wall -g
clean:
rm -f ex4

BIN
learncthehardway/4/ex4 Executable file

Binary file not shown.

14
learncthehardway/4/ex4.c Normal file
View File

@@ -0,0 +1,14 @@
#include <stdio.h>
/* Warning: This program is wrong on purpose. */
int main()
{
int age = 10;
int height;
printf("I am %d years old.\n");
printf("I am %d inches tall.\n", height);
return 0;
}

BIN
learncthehardway/ex10/a.out Executable file

Binary file not shown.

View File

@@ -0,0 +1,23 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
int i = 0;
// go through each string in argv
for (i = 1; i < argc; i++) {
printf("arg %d: %s\n", i, argv[i]);
}
// Make an array of strings
char *states[] = {
"California", "Oregon",
"Washington", "Texas"
};
int num_states = 4;
for (i = 0; i < num_states; i++) {
printf("states %d: %s\n", i, states[i]);
}
return 0;
}

BIN
learncthehardway/ex14/a.out Executable file

Binary file not shown.

View File

@@ -0,0 +1,42 @@
#include <stdio.h>
#include <ctype.h>
// forward declarations
int can_print_it(char ch);
void print_letters(char arg[]);
void print_arguments(int argc, char *argv[])
{
int i = 0;
for(i = 0; i < argc; i++) {
print_letters(argv[i]);
}
}
void print_letters(char arg[])
{
int i = 0;
for(i = 0; arg[i] != '\0'; i++) {
char ch = arg[i];
if(can_print_it(ch)) {
printf("'%c' == %d ", ch, ch);
}
}
printf("\n");
}
int can_print_it(char ch)
{
return isalpha(ch) || isblank(ch);
}
int main(int argc, char *argv[])
{
print_arguments(argc, argv);
return 0;
}

View File

@@ -0,0 +1,5 @@
instead of doing something like
char name[4] = "zed"
do
char *name = "zed"

View File

@@ -0,0 +1,6 @@
CFLAGS=-Wall -g
clean:
rm -f ex1
all:
ex1

BIN
learncthehardway/exc1/a.out Executable file

Binary file not shown.

View File

@@ -0,0 +1,8 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
puts("Hello world.");
return 0;
}

View File

@@ -0,0 +1,4 @@
CFLAGS=-Wall -g
clean:
rm -f ex1