Skip to content

Commit c30f5a3

Browse files
committed
implementation of the makefile paradigm
1 parent 456b4cf commit c30f5a3

File tree

7 files changed

+83
-43
lines changed

7 files changed

+83
-43
lines changed

headers/main.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "./stringManipulation.h"

headers/stringManipulation.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "./sys_headers.h"
2+
3+
char toLower(char c);
4+
char toUpper(char c);
5+
6+
void printStr(char *str);
7+
void copyStr(char *str, char *data);
8+
void concat(char *dest, char *first_str, char *second_str);
9+
void split(char *str, int pos, char *rest);
10+
void splice(char *str, int pos, int charCoutn);
11+
void slice(char *dest, char *str, int pos, int charCount);
12+
void trim(char *str, char char_to_trim);
13+
void replace(char *str, char *sub, char *new_sub);
14+
15+
int countWords(char *str, char delemeter);
16+
int getLength(char *c);
17+
18+
bool isEmpty(char *str);
19+
bool findSubString(char *str, char *sub);

headers/sys_headers.h

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
#include <stdio.h>
3+
#include <stdbool.h>
4+
#include <assert.h>
5+
#include <stdlib.h>

src/Makefile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# liste des fichiers source
2+
SRC = main.c stringManipulation.c
3+
#SRC = $(wildcard *.c)
4+
5+
# liste des fichiers .o et des dependances (mis dans le repertoire build/)
6+
OBJ = $(addprefix build/,$(SRC:.c=.o))
7+
DEP = $(addprefix build/,$(SRC:.c=.d))
8+
9+
# nom du compilateur
10+
CC = gcc
11+
12+
# nom de l'executable
13+
EXE = main
14+
15+
# flags de compilation (CFLAGS) et d'edition de liens (LDFLAGS)
16+
CFLAGS += -Wall -MMD -g -O2
17+
LDFLAGS= #-lm
18+
19+
# regle principale: generer l'executable
20+
all: $(OBJ)
21+
$(CC) -o $(EXE) $^ $(LDFLAGS)
22+
23+
# regle generique pour produire un fichier .o a partir d'un fichier .c
24+
build/%.o: %.c
25+
@mkdir -p build
26+
$(CC) $(CFLAGS) -o $@ -c $<
27+
28+
# regle generique pour faire du nettoyage
29+
clean:
30+
rm -rf build core *.gch
31+
32+
# inclusion automatique du fichier de dependances
33+
-include $(DEP)

src/main.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "../headers/main.h"
2+
3+
4+
int main(void)
5+
{
6+
char *sub = malloc(10 * sizeof(char));
7+
char *str = malloc(20 * sizeof(char));
8+
char *dest = malloc(29 * sizeof(char)); // 10 + 20 -1
9+
10+
copyStr(str, "theretherethere");
11+
12+
replace(str, "there", "body!");
13+
14+
printf("-----\n");
15+
printStr(str);
16+
17+
/* deallocation */
18+
19+
str != NULL ? free(str) : true;
20+
sub != NULL ? free(sub) : true;
21+
return 0;
22+
}

stringManipulation.c renamed to src/stringManipulation.c

+3-43
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,11 @@
1+
#include "../headers/stringManipulation.h"
2+
3+
14
/*
25
IN THIS FILE WE WILL IMPLEMENT ALL THE BASIC FUNCTIONS OF STRING MANIPULATION ON C PROGRAMMING LANGUAGE.
36
47
*/
58

6-
#include <stdio.h>
7-
#include <stdbool.h>
8-
#include <assert.h>
9-
#include <stdlib.h>
10-
11-
char toLower(char c);
12-
char toUpper(char c);
13-
14-
void printStr(char *str);
15-
void copyStr(char *str, char *data);
16-
void concat(char *dest, char *first_str, char *second_str);
17-
void split(char *str, int pos, char *rest);
18-
void splice(char *str, int pos, int charCoutn);
19-
void slice(char *dest, char *str, int pos, int charCount);
20-
void trim(char *str, char char_to_trim);
21-
void replace(char *str, char *sub, char *new_sub);
22-
23-
int countWords(char *str, char delemeter);
24-
int getLength(char *c);
25-
26-
bool isEmpty(char *str);
27-
bool findSubString(char *str, char *sub);
28-
29-
int main(void)
30-
{
31-
char *sub = malloc(10 * sizeof(char));
32-
char *str = malloc(20 * sizeof(char));
33-
char *dest = malloc(29 * sizeof(char)); // 10 + 20 -1
34-
35-
copyStr(str, "theretherethere");
36-
37-
replace(str, "there", "body!");
38-
39-
printf("-----\n");
40-
printStr(str);
41-
42-
/* deallocation */
43-
44-
str != NULL ? free(str) : true;
45-
sub != NULL ? free(sub) : true;
46-
return 0;
47-
}
48-
499
char toUpper(char c)
5010
{
5111
assert((int)c >= 97);

stringManipulation

-21.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)