In the following code, I keep crashing after the last for-loop. I can't figure out by debugging with Netbeans.. The for loop works, and prints what I want to be printed but then the program crashes instead of succesfull termination. Could you please help (I know about gets, I will try fgets soon)??
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *str,**string,buffer[50],temp[2];
int i,j,size,counter;
size=1;
string=(char**) calloc(size,sizeof(char*));
for (i=0; i<size; i++) string[i]=(char*)malloc(50*sizeof(char));
printf("\nGimme strings, terminate input with x");
i=0;
gets(string[i]);
temp[0]=120;//x
temp[1]='\0';
size=2;
while(strcmp(string[i],temp)!=0)
{
string=realloc(string,size*sizeof(char**));
i++;
string[i]=malloc(50*sizeof(char));
gets(string[i]);
size++;
counter++;
}
for(i=0; i<=counter; i++) printf("\n%s",string[i]);
return 0;
}