C Language exercises and C Language exercises
/*
Compile a function to reverse the input string. Provide complete input for this function using a loop statement
Program.
*/
# Include <stdio. h>
# Include <string. h>
Void fanxu (char * zf); // Reverse Order Function
Int main (void)
{
Char a [80];
Do
{
Gets ();
Fanxu ();
Printf ("Continue? (y/n ):");
Gets ();
} While (*! = 'N ');
Return 0;
}
/* // Method 1:
Void fanxu (char * zf)
{
Char * pc;
Pc = zf;
While (* ++ pc)
{
Continue;
}
Pc --;
While (pc> = zf)
{
Putchar (* pc );
Pc --;
}
Putchar ('\ n ');
}
*/
/* // Method 2:
Void fanxu (char * zf)
{
Char * pc;
Pc = zf + strlen (zf );
While (-- pc> = zf)
{
Putchar (* pc );
}
}
*/
/* // Method 3:
Void fanxu (char * zf)
{
Int I, n;
Char temp;
For (n = 0; * (zf + n )! = '\ 0'; n ++)
Continue;
N --;
For (I = 0; I <n-I; I ++)
{
Temp = zf [I];
Zf [I] = zf [n-I];
Zf [n-I] = temp;
}
Puts (zf );
}
*/
// Method 4:
Void fanxu (char * zf)
{
Int I, n;
Char temp;
N = strlen (zf)-1;
For (I = 0; I <n-I; I ++)
{
Temp = zf [I];
Zf [I] = zf [n-I];
Zf [n-I] = temp;
}
Puts (zf );
}