Template on Linux

Version 1.

Makefile
1
main: main.o
2
<TAB>gcc main.o -o main
3
4
main.o: main.c
5
<TAB>gcc main.c -Wall -Werror -c
6
7
clean:
8
<TAB>rm -rf *.o
Copied!
main.c
1
#include <stdio.h>
2
3
int my_func(const char* s1, const char* s2){
4
//code
5
}
6
7
8
int main() {
9
//code
10
return 0;
11
}
Copied!

Version 2.

1
char* URLify(char* testStr, int len){
2
3
...
4
return testStr;
5
}
6
7
8
int main(int argc, char *argv[]) {
9
10
// check the number of argc
11
if (argc != 2 ) {
12
printf("Correct Syntax: ./urlify \"string\" ");
13
exit(1);
14
}
15
16
//argv[0] == ./urlify
17
//argv[1] == "string"
18
int length = strlen(argv[1]);
19
char *sentence = (char *) malloc( sizeof(char) * (length * 3 + 1) );
20
sentence = argv[1];
21
22
printf("Input: %s\n", sentence);
23
printf("Output: %s\n", URLify(sentence, length));
24
25
return 0;
26
}
Copied!
Last modified 3mo ago
Copy link