问题
#include <stdio.h>
int main()
{
int N, i, j, k, z, v, x, c;
printf("Determine the number of your words: \n");
scanf("%d", &N);
char dict[50][50];
char tmp[50];
for(i=0; i<N; i++)
{
printf("Determine your %d. word: \n", i+1);
scanf("%49s", &dict[i]);
}
for(j=0; N-1; j++)
{
for(k=0; N-i; j++)
{
if(dict[k][0]>dict[k+1][0])
{
for(z=0; z<50; z++)
{
tmp[z]=dict[k][z];
}
for(v=0; v<50; v++)
{
dict[k][v] = dict[k+1][v];
}
for(x=0; x<50; x++)
{
dict[k][x]=tmp[x];
}
}
}
}
for(c=0; c<N; c++)
{
printf("%s \n", dict[c]);
}
return 0;
}
So in my first semestr as a Ce student in college our task is to write a C code that (bubble)sort the strings in a 2D array according to their first characters position in the alphabet by only using the <stdio.h> library and I cannot get any resluts. I do not wish any answers. But I would be glad to be enlightened about the reasons I get this results. NOTES:we haven't really procceded on the terms of coding(which is the subject of the second semestr) so we don't create our own functions yet. I also cannot use any additional headings like int main void. I'm allowed to write code under only int main
来源:https://stackoverflow.com/questions/65344720/how-to-write-a-c-code-that-bubblesorts-the-strings-in-a-2d-array