Write a function reverse() that accepts a string and reverses it
as example reverse("hello") would return "olleh"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
char* reverse(char *base)// passing array to a function that returns pointer to character | |
{ | |
int i=0; | |
int j=strlen(base)-1; | |
char temp; | |
while(i!=j) | |
{ | |
temp=base[i]; | |
base[i]=base[j]; | |
base[j]=temp; | |
i++; | |
j--; | |
} | |
return base; | |
} | |
int main() | |
{ | |
char array[5]="hello"; | |
puts(reverse(array)); | |
return 0; | |
} |
No comments:
Post a Comment