Hello....
I've tried adding the name of some countries into country list. So I have to allocate a layered address of char (pointer) to do this properly. And run the program... Crash !!! We are sorry about this inconvenience...??????
No compling & linking errors & warnings, why this caused??
I'm don't know how to make my code become correct. Perhaps something in my code makes my program sad and... cry !!!
// What are your favorite countries?
char ** strCountrylist;
char strInp[256]; //Input
int nCount = 0;
bool bAllow = true; //Allows to continue parsing (inputing) or not
int main(){
strCountrylist = newchar*[256]; //allocating the buffer
// Start the interview
while(bAllow){
printf("Your favorite country :");
scanf("%s", strInp);
printf("\n");
if(!stricmp(strInp, "none"))bAllow = false;
else{
strcpy(strCountrylist[nCount], strInp);nCount++;}
}
//printing the results
printf("Your favorite countries you have added :");
for(int i = 0; i < nCount;i++)
printf(strCountrylist[i]);
return 0;
}
And... It's.. Crashed !!!
Does anyone know this crash?? The code seems is wrong somewhere.
I haven't seen this error before so I don't know how to solve it...
On line 15, you copy to strCountrylist[nCount] which has not been allocated yet. Any input over 255 characters will probably break the program as well.