Reverse a character array using recursion in C -


here's code , can't seem figure out how make function array argument.

#include <stdio.h> #include <math.h> #include <stdlib.h>  int main(int argc, char *argv[]) {        char strarray[30] = "print string backward.";        puts("");       stringreverse(strarray);        return(0); }   void stringreverse(char strarray[]) {       if(strarray != "\n") {         stringreverse(&strarray)         printf("%s", strarray)     } } 

first, need return value.

then, algorithm should do? run until final of string , return variable variable in reverse 1 parameter, need pass parameter shorter every loop.

like this:

#include "stdafx.h" #include "stdio.h" #include "stdlib.h" #include "string.h"  void stringreverse(char strarray[], int i) {     if (strarray[0] != null)     if (strarray[0] != '\0') {         int c = 0;         char str[30];         while (c < strlen(strarray)) {             str[c] = strarray[2 + c -1];             c++;         }         str[c] = '\0';         stringreverse(str);     }            printf("%c", strarray[0]); }  int main(int argc, char *argv[]) {     char strarray[30] = "print string backward.";    stringreverse(strarray, 0);    printf("\n\n");    system("pause");    return(0); } 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -