I am trying to do a more complex program, but I stumbled across a problem with one of my functions. I'll post a simpler version of the function written as a program here:
int main()
{
int p,i=0;
char *q;
char x[3][60], y[3][60];
strcpy(x[0],"Hello! : How are you today?");
strcpy(x[1],"Fine! : How about you?");
for(i=0;i<2;i++)
{ q=strstr(x[i],": ");
p=q-x[i];
strncpy(y[i],x[i],p);
y[i][p]='\0';
printf("%s \n", y[i]);
}
getch();
}
This program works as it should (it needs to display the string found in x[0] and x[1] untill it finds ": "), except it crashes everytime (I use DEV C++ as compiler). Can anyone tell me what the problem is here?