Hi everyone,
I am practicing the use of realloc() in a practice function so that I will be able to use it in my real program. The aim for me right now is to concatenate 2 strings but I continue to get segmentation fault from extending the memory allocated to the first string, which should be needed for making it longer through concatenation. Here is my code, thanks for all the help!
Any comments, suggestions, advice to improve coding ability are greatly appreciated!
Code:
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char **argv) {
char *in;
char *im;
im="/0\0";
in="/5\0";
printf("in=%s im=%s in=%d im=%d\n len(in+im)=%d",in,im,strlen(in),strlen(im),strlen(im)+strlen(in));
in=realloc(in,strlen(in)+strlen(im)+1);
// strcat(in,im);
printf("in=%s\n",in);
}