- 2
Can anyone help me in solving extra terrestrial code in c by using string reverse function.
4 odpowiedzi
+ 1
show your attempt Guntumadugu Rakesh
+ 1
Ive had difficulty with this one too... Stick to it for 6 montha and problems like this will seem easy.
0
strrev is not a C standard function , so in most of the compiler it doesn't work !
so , solve by counting number of characters in string (by strlen()) , apply loop from last (length of string) to first !
Ex:
char str[100];
scanf("%s",str);
int length=strlen(str);
/*strlen counts no.of characters in string except null , use string.h header file .*/
for(int i=length-1 ; i>=0 ; i--)
printf ("%c",str[ i ] );
- 2
#include <stdio.h>
#include<string.h>
int main() {
char str1[20];
scanf ("%s",str1);
strrev (str1);
printf("%s",str1);
return 0;
}