I'm trying to figure out how to use pointers and strings. I get segmentation fault when I run this program. I just don't understand why. I'm using gcc version 4.4.3 (Ubuntu).
Code:
#include <stdio.h>
char *my_strcpy(char *destination, char *source) {
char *p = destination;
while (*source != '\n') {
*p++ = *source++;
}
*p = '\0';
return destination;
}
char strA[80] = "Test string";
char strB[80];
int main(void) {
char *pA; // a pointer to type character
char *pB;
char *pC;
pA = strA; // point pA at string A
pB = strB;
pC = my_strcpy(strB,strA);
return 0;
}