Fixed all those make files

master
Drew Bednar 4 years ago
parent 743f5d215d
commit 46f0946e62

1
.gitignore vendored

@ -33,3 +33,4 @@
*.dSYM/ *.dSYM/
.idea/ .idea/
.vscode/

@ -0,0 +1,12 @@
.PHONY: clean
P=erf
OBJECTS= erf.o
CFLAGS = -g -Wall -O3
LDLIBS=''
CC=gcc
$(P): $(OBJECTS)
clean:
rm -f *.o $(P)

Binary file not shown.

@ -0,0 +1,6 @@
CLEANSUBDIRS ?= types structs static pointers hello headers functions file_io env_vars
cleanall:
@for subdir in $(CLEANSUBDIRS); do \
(cd $$subdir && $(MAKE) clean) || exit 1; \
done

@ -1,7 +1,11 @@
P= P=env
OBJECTS= OBJECTS=
CFLAGS = -g -Wall -O3 CFLAGS = -g -Wall -O3
LDLIBS= LDLIBS=
CC=gcc CC=gcc
$(P): $(OBJECTS) $(P): $(OBJECTS)
clean:
rm -f *.o $(P)
rm -rf env.dSYM/

Binary file not shown.

@ -1,14 +1,18 @@
#include <stdlib.h> //getenv, atoi #include <stdlib.h> //getenv, atoi
#include <stdio.h> //printf #include <stdio.h> //printf
int main(){ int main()
{
// pointer to a char // pointer to a char
char *repstext=getenv("reps"); char *repstext = getenv("reps");
// atoi reads in the string and converts it to a integer value.
// This is the tenary operator 'condition ? value_if_true : value_if_false'
int reps = repstext ? atoi(repstext) : 10; int reps = repstext ? atoi(repstext) : 10;
char *msg = getenv("msg"); char *msg = getenv("msg");
if (!msg) msg = "Hello."; if (!msg)
msg = "Hello.";
for (int i=0; i< reps; i++) for (int i = 0; i < reps; i++)
printf("%s\n", msg); printf("%s\n", msg);
} }

@ -4,4 +4,4 @@ csv_writer:
gcc -o csv_writer csv_writer.c gcc -o csv_writer csv_writer.c
clean: clean:
rm -f csv_writer rm -f csv_writer *.csv

Binary file not shown.

@ -4,10 +4,11 @@
#define FILE_EXTENSION ".csv" #define FILE_EXTENSION ".csv"
int main(int argc, char const *argv[])
{
int main(int argc, char const *argv[]){ if (argc <= 1)
{
if (argc <= 1){
fprintf(stderr, "Failed to provide a csv file\n"); fprintf(stderr, "Failed to provide a csv file\n");
exit(1); exit(1);
} }
@ -15,8 +16,9 @@ int main(int argc, char const *argv[]){
size_t file_len = strlen(argv[1]); size_t file_len = strlen(argv[1]);
/*char pointer of*/ /*char pointer of*/
char * FILE_NAME = malloc(file_len + 1); char *FILE_NAME = malloc(file_len + 1);
if (FILE_NAME == NULL){ if (FILE_NAME == NULL)
{
fprintf(stderr, "Failed to allocate memory for file name!"); fprintf(stderr, "Failed to allocate memory for file name!");
exit(1); exit(1);
} }
@ -25,7 +27,8 @@ int main(int argc, char const *argv[]){
strcpy(FILE_NAME, argv[1]); strcpy(FILE_NAME, argv[1]);
/*Returns a pointer to the location the substring if found*/ /*Returns a pointer to the location the substring if found*/
if (strstr(FILE_NAME, FILE_EXTENSION) == NULL ){ if (strstr(FILE_NAME, FILE_EXTENSION) == NULL)
{
fprintf(stderr, "What the fuck are you doing? That %s isn't a csv file!\n", FILE_NAME); fprintf(stderr, "What the fuck are you doing? That %s isn't a csv file!\n", FILE_NAME);
free(FILE_NAME); free(FILE_NAME);
FILE_NAME = 0; FILE_NAME = 0;
@ -35,9 +38,9 @@ int main(int argc, char const *argv[]){
char name[128], phone_number[13]; char name[128], phone_number[13];
// puts(FILE_NAME); // puts(FILE_NAME);
FILE *_target_file = fopen(FILE_NAME, "a"); FILE *_target_file = fopen(FILE_NAME, "a");
if (_target_file == NULL){ if (_target_file == NULL)
{
exit(1); exit(1);
} }
puts("Name: "); puts("Name: ");
@ -46,7 +49,7 @@ int main(int argc, char const *argv[]){
scanf("%s", phone_number); scanf("%s", phone_number);
printf("Appending %s and %s to %s", name, phone_number, FILE_NAME); printf("Appending %s and %s to %s", name, phone_number, FILE_NAME);
fprintf(_target_file,"%s,%s\n", name, phone_number); fprintf(_target_file, "%s,%s\n", name, phone_number);
fclose(_target_file); fclose(_target_file);
/*clean up*/ /*clean up*/
free(FILE_NAME); free(FILE_NAME);

@ -1 +0,0 @@
Margot,517-775-7040
1 Margot 517-775-7040

@ -0,0 +1,12 @@
.PHONY: clean
P=cube
OBJECTS= cube.o
CFLAGS = -g -Wall -O3
LDLIBS=''
CC=gcc
$(P): $(OBJECTS)
clean:
rm -f *.o $(P)

Binary file not shown.

@ -1,5 +1,5 @@
CFLAGS=-Wall -O3 CFLAGS=-Wall -O3
PROGRAMS=simple_pointer adv_pointer PROGRAMS=simple_pointer adv_pointer char_pointer
all: $(PROGRAMS) all: $(PROGRAMS)
@ -9,6 +9,9 @@ simple_pointer:
adv_pointer: adv_pointer:
gcc -o adv_pointer $(CFLAGS) adv_pointer.c gcc -o adv_pointer $(CFLAGS) adv_pointer.c
char_pointer:
gcc -o char_pointer $(CFLAGS) char_pointer.c
# NOT IMPLEMENTED # NOT IMPLEMENTED
#array_pointer: #array_pointer:
# gcc -o array_pointer -Wall -O1 array_pointer.c # gcc -o array_pointer -Wall -O1 array_pointer.c

Binary file not shown.

@ -0,0 +1,33 @@
#include <stdio.h>
#define DOLLARS 0x24;
// Example of function declaration. This is what the preprocessor does with the header files
void set_to_y(char *p);
int main()
{
char my_char = 'a';
char *p_char;
p_char = &my_char;
printf("The value of *p_char is set to %c\n", *p_char);
set_to_y(p_char);
printf("Lets check the value of my_char: %c\n", my_char);
printf("You, know what I want to just muck with your memory directly\n");
//derefence the location and just set the byte we want
*p_char = DOLLARS;
printf("So all your bits now should show my_char as $ DOLLARS. Lets see: %c\n", my_char);
return 0;
}
// This is function definition
void set_to_y(char *p)
{
fprintf(stdout, "Setting the value at address %p from %c to y\n", &p, *p);
*p = 'y';
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,12 @@
.PHONY: clean
P=types
OBJECTS= types.o
CFLAGS = -g -Wall -O3
LDLIBS=''
CC=gcc
$(P): $(OBJECTS)
clean:
rm -f *.o $(P)

@ -3,8 +3,6 @@
//Type definition //Type definition
typedef unsigned char byte; typedef unsigned char byte;
int main(int argc, char const *argv[]) int main(int argc, char const *argv[])
{ {
int i = 123; int i = 123;
@ -30,7 +28,7 @@ int main(int argc, char const *argv[])
//we have to cast the result of sizeof because it returns a value whose size is large enough //we have to cast the result of sizeof because it returns a value whose size is large enough
//to hold a pointer value, but the fundamental types will never be that big so we cast //to hold a pointer value, but the fundamental types will never be that big so we cast
printf("The value of i: %d (%d) bytes\n", i, (int) sizeof(int)); printf("The value of i: %d (%d) bytes\n", i, (int)sizeof(int));
//this will tell us that int is 4 bytes and running in a 32 bit address space //this will tell us that int is 4 bytes and running in a 32 bit address space
return 0; return 0;

Loading…
Cancel
Save