init commit
This commit is contained in:
4
learncthehardway/3/Makefile
Normal file
4
learncthehardway/3/Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
CFLAGS=-Wall -g
|
||||
|
||||
clean:
|
||||
rm -f ex1
|
BIN
learncthehardway/3/ex3
Executable file
BIN
learncthehardway/3/ex3
Executable file
Binary file not shown.
12
learncthehardway/3/ex3.c
Normal file
12
learncthehardway/3/ex3.c
Normal 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;
|
||||
}
|
4
learncthehardway/4/Makefile
Normal file
4
learncthehardway/4/Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
CFLAGS=-Wall -g
|
||||
|
||||
clean:
|
||||
rm -f ex4
|
BIN
learncthehardway/4/ex4
Executable file
BIN
learncthehardway/4/ex4
Executable file
Binary file not shown.
14
learncthehardway/4/ex4.c
Normal file
14
learncthehardway/4/ex4.c
Normal 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
BIN
learncthehardway/ex10/a.out
Executable file
Binary file not shown.
23
learncthehardway/ex10/ex10.c
Normal file
23
learncthehardway/ex10/ex10.c
Normal 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
BIN
learncthehardway/ex14/a.out
Executable file
Binary file not shown.
42
learncthehardway/ex14/ex14.c
Normal file
42
learncthehardway/ex14/ex14.c
Normal 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;
|
||||
}
|
5
learncthehardway/ex9/notes
Normal file
5
learncthehardway/ex9/notes
Normal file
@@ -0,0 +1,5 @@
|
||||
instead of doing something like
|
||||
|
||||
char name[4] = "zed"
|
||||
do
|
||||
char *name = "zed"
|
6
learncthehardway/exc1/Makefile
Normal file
6
learncthehardway/exc1/Makefile
Normal file
@@ -0,0 +1,6 @@
|
||||
CFLAGS=-Wall -g
|
||||
|
||||
clean:
|
||||
rm -f ex1
|
||||
all:
|
||||
ex1
|
BIN
learncthehardway/exc1/a.out
Executable file
BIN
learncthehardway/exc1/a.out
Executable file
Binary file not shown.
8
learncthehardway/exc1/ex1.c
Normal file
8
learncthehardway/exc1/ex1.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
puts("Hello world.");
|
||||
|
||||
return 0;
|
||||
}
|
4
learncthehardway/exc2/Makefile
Normal file
4
learncthehardway/exc2/Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
CFLAGS=-Wall -g
|
||||
|
||||
clean:
|
||||
rm -f ex1
|
Reference in New Issue
Block a user