The following program is supposed to sort eight strings in alphabetical order, but its not functioning properly. Can anyone please debug this

void main()
{
	char *p[8], *s;
	int i,j,t;
	clrscr();
	printf("Enter the strings:\n");
	for(i=0;i<8;i++)
		gets(p[i]);
	for(i=0;i<8;i++)
	{
	       for(j=i+1;j<8;j++)
	       {
			t=strcmp(p[i],p[j]);
			if(t>0)
			{
				s=p[i];
				p[i]=p[j];
				p[j]=s;
			}
	       }
	}
	printf("\nSorted strings:\n");
	for(i=0;i<8;i++)
		puts(p[i]);
	getch();
}

Please help me. Its a spooky program. It works fine if we initialize the string p where it is declared, but does not work properly if we get the strings by gets() or scanf().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.