Skip to content
Snippets Groups Projects
Commit a6cadd6d authored by tom.ryser's avatar tom.ryser :carousel_horse: Committed by orestis.malaspin
Browse files

Resolve "add makefile with structure"

parent c4e5b4ad
No related branches found
No related tags found
1 merge request!3Resolve "add makefile with structure"
# Object files
*.o
*.exe
# Executables
main
Makefile 0 → 100644
CC:=gcc
CFLAGS:=-g -Wall -Wextra -pedantic -fsanitize=address
LDFLGS:=-fsanitize=address
NAME:=stack
$(NAME): main.o $(NAME).o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
test: $(NAME)_test.o $(NAME).o
$(CC) $(CFLAGS) -o $@ $^
./test
$(NAME).o: $(NAME).h
$(NAME)_test.o: $(NAME).h
.PHONY: clean
clean:
rm -f *.o $(NAME) test
# stack
# Stack
```
📦project
┣ 📜main.c
┣ 📜stack.c
┣ 📜stack.h
┣ 📜.gitignore
┣ 📜Makefile
┗ 📜README.md
```
main.c 0 → 100644
#include "stack.h"
#include <stdio.h>
#include <stdlib.h>
int main(void) {
return EXIT_SUCCESS;
}
#include "stack.h"
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
#define DEFAULT_CAPACITY 4
void stack_init(stack *s)
{
void stack_init(stack *s) {
s->top = -1;
s->capacity = DEFAULT_CAPACITY;
s->data = malloc(sizeof(int) * DEFAULT_CAPACITY);
......@@ -38,12 +37,12 @@ void stack_peek(stack s, int *value){
}
void stack_print(const stack s) {
//TODO: replace if statement with following as soon as relevant function is implemented
//if (!stack_is_empty()) {
// TODO: replace if statement with following as soon as relevant function is
// implemented if (!stack_is_empty()) {
if (s.top >= 0) {
printf(" TOP\n--------------------\n");
for (int *spot = s.data + s.top; spot >= s.data; --spot) {
printf("%8d | %12d\n", spot - s.data, *spot);
printf("%8ld | %12d\n", spot - s.data, *spot);
}
printf("--------------------\n BOTTOM\n");
} else {
......@@ -60,7 +59,6 @@ void stack_clone(stack s, stack *clone) {
}
}
int get_length(stack s)
{
int get_length(stack s) {
return s.top + 1;
}
......@@ -19,3 +19,4 @@ int get_length(stack s);
void stack_print(const stack s);
#endif
#include "minunit.h"
#include "stack.h"
#include <stdlib.h>
MU_TEST(stack_init_test) {
// Arrange
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment