Hello there again. My programm runs swimmingly up until my bubble sort. The error I am getting is "Lvlalue required in function main" and I'm not to sure what that means. It is right at the bottom. I am also not to sure if I have the number of times it sorts correct. (It needs to loop N times, where N is the number of words the user wants to enter)
(commenting out the bubble sort makes the program compilable, if you need to see what it should do).
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char **p;
char size[20];
char buff[21];
char temp[21];
int N;
int j,i,k,l,m,d,s,a,b;
int main()
{
do{
d=0;
printf("How many words would you like: ");
fflush(stdout);
for(j=0; j<20; j++)
{
size[j]=fgetc(stdin);
if (size[j]=='\n')
{
size[j]='\0';
break;
}
}/* end j-loop */
if (j==0){
printf("That input is empty.\n");
d=1;
}
if (j==20) {
printf("That input is too long.\n");
while(fgetc(stdin)!='\n');
d=1;
}
}while(d!=0);
printf("You want %d words.\n", atoi(size));
N=atoi(size);
p=(char**)malloc(N*sizeof(char*));
if (p==NULL)
{
printf("Memory error");
exit(0);
}
for (i=0; i<N; i++)
p[i]=(char*)malloc(21*sizeof(char));
if (p[i]==NULL)
{
printf("Memory error");
exit(0);
}
printf("Do not enter more than 20 characters.\n");
for(k=0; k<N; k++)
{
A:printf("Enter a word: ");
fflush(stdout);
for(m=0; m<21; m++)
{
buff[m]=fgetc(stdin);
if (buff[m]=='\n')
{
buff[m]='\0';
break;
}
}
if (m>=21)
{
printf("Word is more than 20 characters.\n");
while(fgetc(stdin)!='\n');
goto A;
}
if (m==0)
{
printf("That input is empty\n");
goto A;
}
strcpy(p[k],buff);
}
printf("\n");
printf("Your unsorted list of Names:\n");
k=0;
for(k=0; k<N; k++)
printf("%s\n",p[k]);
for (a=N; a>0; a--)
{
for (b=0; b<a; b++)
{
if(strcmp(p[b],p[b+1])>0)
{
temp=p[b];
p[b]=p[b+1];
p[b+1]=temp;
}
}
}
printf("\n");
printf("Your sorted list of Names:\n");
k=0;
for(k=0; k<N; k++)
printf("%s\n",p[k]);
return 0;
}