compile: gcc test_list.c list.c run: ./a.outSample compilation with Valgrind (reports memory erros AND line numbers). You must COMPILE with the -g flag (so gcc -g, not just gcc). If you change the code, before rerunning Valgrind, recompile (with the gcc command to create the new a.out file). See above Minimal Valgrind Tutorial - for examples of Valgrind output for correct code (with no memory errors) and code with memory errors.
compile: gcc -g test_list.c list.c run (with user input): valgrind --leak-check=full ./a.out run (with input redirection from file data1.txt, BUT NOT APPLICABLE HERE): valgrind --leak-check=full ./a.out < data1.txt
Sample compilation: either with lists: gcc graph_main.c graph_list.c list.c or with matrices: gcc graph_main.c graph_matrix.c twoD_arrays.c run: valgrind --leak-check=full ./a.out
char* table[10]; char buff[100]; for(int i = 0; i<10; i++){ printf("%s", "Enter a string: "); scanf("%s", buff); table[i] = buff; }
N Min Max val1 val2 val3.... valNwhere N indicates how many numbers will be on the next line separated by a space, and Min, Max give the range for those values (Min ≤ vali ≤ Max). E.g.
7 0 25 6 21 9 3 15 0 9
Compile: gcc -o userimp user_input.c Run one way (it will get the input from the user): ./userimp.exe Run another way (it will get the input with file redirection). Do not change the code or anything else. make sure that the executable and hello_data1.txt are in the same folder: ./userimp.exe < hello_data1.txt You should get the output: Please enter a word (less than 100 letters):Please enter another word (less than 100 letters):Please enter another word (less than 100 letters):You entered first: elephant ByeYou entered second: house ByeYou entered third: 3 Bye Another sample run ./userimp.exe < hello_data2.txt You should get the output: Please enter a word (less than 100 letters):Please enter another word (less than 100 letters):Please enter another word (less than 100 letters):You entered first: elephant ByeYou entered second: house ByeYou entered third: 3 Bye
ls hello.c gcc -c hello.c ls hello.c hello.o gcc -o hello.exe hello.o ls hello.c hello.exe hello.o ./hello.exe Hello. The program is running fine.Articles on compile vs link: