Home > Back-end >  C language array
C language array

Time:09-26

From the keyboard input of a string to a character array, and then press reverse again in the array, for example: the original order of abcdefg, asking to gfedcba to deposit, will reverse the string output to the screen, and written to a file out. TXT,

CodePudding user response:

This is very simple, three department, string, string reverse, written to the file, it is the basis of c

CodePudding user response:

His best to write about, no matter what to write to write wrong, or at least trying, trying to ~

CodePudding user response:

 void switchString arr (char *) 
{
Char TMP.
Int len=strlen (arr);
int i=0;
Int j=len - 1;
for(i=0; i{
TMP=arr [I];
Arr=arr [I] [j];
Arr [j]=TMP;
}

}
Void reverseString ()
{
Char tmpStr [32].
The scanf (" % s ", tmpStr);
SwitchString (tmpStr);
Printf (" % s \ r \ n ", tmpStr);
}

CodePudding user response:

# include & lt; Stdio. H>
# include & lt; String. H>

Int main ()
{

Char STR [50]={' 0 '};
Char res [50]={' 0 '};
int index=0;
gets(str);

For (int I=strlen (STR) - 1; I & gt;=0; I -)
{
Res=STR [index] [I];
Putchar (STR [I]);
Index++;
}

The FILE * fp=NULL;
Fp=fopen (" out. TXT ", "w");
The fputs (res, fp);
printf("\n");
Printf (" the file out. TXT write into % s \ n ", res);
fclose(fp);

return 0;
}
  • Related