#include<stdio.h>
#include<conio.h>
#include<malloc.h>
int main()
{
int i=0,j=0,n=0;
char *a,**b;
a=(char *)malloc(sizeof(char)*50);
printf("Enter your text\n");
gets(a);
while(a[i]!='\0')
{
*(b+n)=(char *)malloc(sizeof(char)*20); //error
for(j=0;a[i]!=' ';i++,j++)
{
*(*(b+n)+j)=*(a+i);
}
i++;
n++;
}
printf("Words in given text are \n");
for(i=0;i<n;i++)
{
puts(*(b+i));
printf("\n");
}
printf("Possibile combinations are \n\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(j!=i)
{
puts(b[i]);
printf(" ");
puts(b[j]);
printf("\n");
}
}
}
getch();
}
Above code is for separating words from a given line of text and to produce all possible two word combinations. When I execute this program in dev-cpp
*(b+n)=(char *)malloc(sizeof(char)*20);
produces an access violation.Actually what is wrong here. When i execute same program in turbo c, it does not produce expected output. Can you help me?