1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include<string.h>
#include<stdio.h>
#include <conio.h>
int z,x,y=1,i=0,j=0; // do try to avoid global variables
char let[20][10],temp[100];
int alpha();
int arr();
main()
{
clrscr();
x = 0; // remember to initialize x, you didn't initialize it
while(x!=10)
{
printf("Input %d: ",y);
scanf("%s",&let[x]);
x++;
y++;
}
clrscr();
printf("\nWORDS BEFORE SORTING:\n\n");
for(x=0;x!=10;x++)
{
printf("%s\n",let[x]);
}
alpha();
printf("\nWORDS AFETER SORTING:\n\n");
for(x=0;x!=10;x++)
{
printf("%s\n",let[x]);
}
getch();
return 0; // don't forget the return
}
int alpha()
{
//use braces in nested structures for less confusion. You left out a few.
for(i=0;i!=10;i++)
{
for(j=i+1;j!=10;j++)
{
if(strncmp(let[i],let[j],1)==0)
{
z=2;
arr();
strcpy(temp,let[i]);
strcpy(let[i],let[j]);
strcpy(let[j],temp);
}
else if(strncmp(let[i],let[j],1)>0)
{
strcpy(temp,let[i]);
strcpy(let[i],let[j]);
strcpy(let[j],temp);
}
}
}// end for
}// end alpha
int arr()
{
while(z!=15)
{
if(strncmp(let[i],let[j],z)==0)
{
z++;
}
else
{
i++;
exit(0); // exit needs an integer parameter
}
}
}// end arr
|