Exercise 1-19 writes the function reverse (s), reversing the order of characters in the string s. Use this function to write a program that reverses the order of characters in one input line at a time.
The code is as follows:
#include <stdio.h>//contains information about the standard library. #defineMAXLINE 10//the maximum number of characters per line is 1000. intGetlineCharLine[],intmaxline);voidReverseCharLine[],intlen);intMain ()//defines a function named Main, which does not accept parameter values. { intLen; CharLine[maxline]; while(len = getline (line, MAXLINE)) >0) {Reverse (line, Len); } getchar (); //prevent the console from flashing through, you need to accept any characters after you close the console. return 0;//returns a shape to the execution environment, and 0 represents a successful execution. }intGetlineCharS[],intLim) { intc, I; for(i =0; I < Lim-1&& (c = GetChar ())! = EOF && c! ='\ n'; ++i) {s[i]=C; if(c = ='\ n') {S[i]=C; ++i; }} S[i]=' /'; returni;}voidReverseCharS[],intLen) { inti; intc =0; //loops forward the character array from the back. for(i = len-1; I >=0; i--) {Putchar (s[i]); if(i = =0) printf ("\ n"); }}
Personal Understanding:
The main practice is to customize the declaration and implementation of a function, and practice the reverse array.
C Programming language Exercises 1-19