Reverse array of characters
Code:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <math.h>
void reverseAr(char ar[], int n);
int main()
{
int choice;
char *abc= ar[];
switch (choice) {
case 1:
reverseAr(ar);
break;
void reverseAr(char ar[], int n)
{
char c;
char *p, *q;
p = ar;
if (!p)
return;
q = p + 1;
if (*q == '\0')
return;
c = *p;
reverseAr(ar[]);
while (*q != '\0') {
*p = *q;
p++;
q++;
}
*p = c;
return;
}
My codes keep couldn't get the reverse array of characters. Do anyone mind to tell me where is my mistake? Thank you in advance.
Reverse array of characters
I couldn't initialize the array as I have to get the array of characters from user input, hence I do not know how to do so.
Code:
void reverseAr(char ar[], int n)
{
int i=0,j;
char temp;
int len = strlen(ar);
if (n==0 || n==1)
return;
else
{
temp=*ar;
*ar=ar[n-1];
ar[n-1]=temp;
}
return reverseAr(ar+1,n-2);
}