Home > Back-end >  Write a program
Write a program

Time:12-04

Have a data file test2-2. In which there is a line of string, the string to a character array, and then a character array arranged a lower values for an even number of elements since the childhood, other elements, requirements, the entire string and output reordering subscript for an even number of elements,
Program test2-2 c, the realization of the function,
Data file test2-2. In the content of the see is as follows: a8V61tHZw # A

CodePudding user response:

File to read and write the reference

I use this app # CSDN# found have technical content of the blog and friends to seek common to "C language file reading and writing (1) - the text file read operation", gathered together at https://blog.csdn.net/zhanghaiyang9999/article/details/107032563? Utm_source=app

CodePudding user response:

For your reference
 
# include & lt; Stdio. H>
# include & lt; Stdlib. H>
# include & lt; String. H>
# define N 256

Int main (void)
{
Int \ [N]={0};
Char a [N]={0}, c={0} [N], ch.
Int I=0, j=0, k=0, count=0;
The FILE * fp=fopen (" test2-2. In ", "r");
If (! Fp)
{
Printf (" the file read failure! \n");
The exit (1);
}

Fscanf (fp, "% s", a);
Count=strlen (a);
Printf (" the original string: % s \ n ", a);

For (I=0; I & lt; The count. I++)
{
If (I % 2==0)
{
Temp [j]=I;
C=a [I] [j];
j++;
}
}
Printf (" the subscript for the even number of elements: % s \ n ", c);


For (I=0; I & lt; J - 1; I++)
{
For (k=0; K & lt; J - 1 - I; K++)
{
If (c [k] & gt; C [k + 1])
{
Ch=c [k].
C=c [k] [k + 1);
C=ch [k + 1];
}
}
}

for (i=0; i{
A [\ [I]] [I]=c;
}
Printf (" sorted string: % s \ n ", a);

fclose(fp);
getchar();
return 0;
}
  • Related