I am making a command line program in C using XCode. When running the program, it initially does what it is supposed to do (asks me for a file path). However, when I type in a valid and existing file path, it gives me the following error:
Program received signal: “EXC_BAD_ACCESS”. sharedlibrary apply-load-rules all (gdb)
I have two warnings in my program, both of which have to do with the function strcat. The warnings are:
warning: implicit declaration of function 'strcat'
and
warning: incompatible implicit declaration of built-in function 'strcat'
I am wondering why my program is not executing properly.
Thanks,
Mike
My code is posted below:
#include "stdlib.h"
int main (void)
{
char *string1;
printf("Type in your file path: ");
scanf("%s", string1);
char *string2 = "tar czvf YourNewFile.tar.gz ";
strcat(string2, string1);
system(string2);
}
Maybe it has to do with allocating the chars?
Examine this line:
and this line:
You have not declared a size for string1, meaning that you will always get an error, fix it with something like this:
char string1[100]If 100 is the maximum length of your input.
Or read your input character by character.
And, to get rid of the warnings, add
#include "string.h"to where your#includestatements are.