An example program that used to demonstrate how to use GDB/LLDB and Valgrind with the tutorial at http://www.afnan.io/debugging-c-with-gdb-and-valgrind/
/* gdb_valgrind_example.c Afnan Enayet | |
* | |
* An example designed to help a user understand how to | |
* use GDB/LLDB and Valgrind | |
* | |
* Functions: | |
* - init_str: a functions that initializes a string | |
* to "hello" | |
* | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
/****** Function prototypes ******/ | |
static void init_str(char *str); | |
/****** Function definitions *****/ | |
/* Initializes and creates a string that says "hello" | |
*/ | |
static void init_str(char *str) | |
{ | |
str = malloc(5); | |
strcpy(str, "hello"); | |
} | |
int main(void) | |
{ | |
// Allocating a string with the literal "hello" | |
char *str = NULL; | |
printf("This next string should be blank...\n"); | |
init_str(str); | |
printf("%s\n", str); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment