Home > Back-end >  According to the dictionary for multiple string collation sequence
According to the dictionary for multiple string collation sequence

Time:10-27


Which is a great god tell me where I was wrong the

#include
#include

The main ()
{
Char * t;
Int I, j, n, p;
Char * s []={" pescal ", "basic", "FORTRAN," "turbo C"};
Printf (" Enter n: ");
The scanf (" % d ", & amp; N);/* the number of input to sort a string n */
for (i=0; i with bubble sort method{
for (j=0; J{
[j] if (STRCMP (s, s) [j + 1] & gt; 0)
{
Strcpy (t, s [j]); [j] strcpy (s, s [j + 1)); Strcpy (s [j + 1), t);
}
}
}
Printf (" % d ", p);
for (i=0; i{
Printf (" % s \ n ", s [I]);
}

return 0;
}

CodePudding user response:

 # include & lt; Stdio. H> 
#include

The main ()
{
Char * t;
Int I, j, n.//p;
Unsigned int arr_len;
//char * s []={" pescal ", "basic", "FORTRAN," "turbo C"};
Const char * s []={" pescal ", "basic", "FORTRAN," "turbo C"};
Printf (" Enter n: ");
The scanf (" % d ", & amp; N);/* the number of input to sort a string n */
Arr_len=sizeof (s)/sizeof (s [0]);
If (n & gt; Arr_len)
N=arr_len;
for (i=0; i with bubble sort method{
for (j=0; J{
[j] if (STRCMP (s, s) [j + 1] & gt; 0)
{
T=(char *) s [j];
S [j]=s [j + 1);
S [m + 1]=t;
[j]//strcpy (t, s);
[j]//strcpy (s, s [j + 1));
[j + 1)//strcpy (s, t);
}
}
}
//printf (" % d ", p);
for (i=0; i{
Printf (" % s \ n ", s [I]);
}

return 0;
}

For your reference ~

The main problems of the building Lord is s understanding of pointer, the original poster is a pointer of the definition of an array, each element is a pointer, and every pointer points to the read-only data segments on a string, and the building Lord at the time of ordering for read-only data write operations, so should appear many mistakes ~

Exchange the position of the pointer to directly can ~

Other problems can be found in the code
  • Related