Im a beginner and at school we have task to split a char array by using pointer. I want to split the name and the birthday (delimiter = '.'). My solution works perfect for the name but doing it for the birthday i get a segmentation fault.
int main(int argc, char *argv[])
{
char *fullname;
char *name;
char *lastname;
char *birthday;
char *day;
fullname = argv[1];
birthday = argv[2];
int i = 0;
int y = 0;
int z = 0;
while(fullname[i] != '.'){
char x = fullname[i];
name[i] = x;
fullname[i] = ' ';
i++;
}
i++;
while(fullname[i] != '\0'){
char x = fullname[i];
lastname[y] = x;
fullname[i] = ' ';
i++;
y++;
}
while(birthday[z] != '.'){
char b = birthday[z];
day[z] = b;
z++;
}
}
Input in commandline (./a is the exe file on cygwin):
./a mister.gold 11.05.2005
Output:
segmentation fault
When i launch the code without the last loop my output is:
mister
gold