Alright, well I would imagine the anwer to this question is quite obvious to anyone who programs in c often. Basically I am trying to use the standard library function strcpy inside of a function I am writing. For some reason when I use strcpy inside of main() it works fine. When I use strcpy outside of main() it compiles fine, but causes a runtime error. I wrote a simple program to demonstrate the problem. The programs runs fine the way it is, but if you uncomment the line in main() that calls testFunction, then it causes a run time error.
Code:#include<stdio.h>
#include<string.h>
void testFunction(char *string);
int main()
{
char *a;
char *b = "test string";
strcpy(a,b);
puts(a);
/*testFunction("test string2"); */
return 0;
}
void testFunction(char *string){
char *a;
strcpy(a, string);
puts(a);
}