Ok, so I'm trying to pass a char pointer to another function. I can do this with a char array, but not with a char pointer. The problem is that I do not know its size, so I can not declare anything about the size inside the main() function.
#include <stdio.h> void ptrch ( char * point) { point = "asd"; } int main() { char * point; ptrch(point); printf("%s\n", point); return 0; }
However, this does not work; these two work:
1)
#include <stdio.h> int main() { char * point; point = "asd"; printf("%s\n", point); return 0; }
2)
#include <stdio.h> #include <string.h> void ptrch ( char * point) { strcpy(point, "asd"); } int main() { char point[10]; ptrch(point); printf("%s\n", point); return 0; }
So, I'm trying to understand the cause and possible solution to my problem.
source share