Created
October 20, 2014 13:54
-
-
Save brijeshb42/52a43c9f8c8b2e30323a to your computer and use it in GitHub Desktop.
str-rev
This file contains hidden or 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> | |
#include <stdlib.h> | |
char *op; | |
void revStr(char *ip){ | |
int ln = strlen(ip); | |
op = malloc(sizeof(char)*(ln+1)); | |
int i,j,u,l; | |
int st = 0; | |
for(i=0;i<ln;i++){ | |
if(i==0 || ip[i-1]==' '){ | |
l = i; | |
st = 0; | |
} | |
if(ip[i]==' '){ | |
u = i-1; | |
st = 1; | |
op[i]=' '; | |
}else if(i==ln-1){ | |
u = i; | |
st = 1; | |
op[ln] = '\0'; | |
} | |
if(st){ | |
for(j=l;j<=u;j++){ | |
op[j] = ip[u-j+l]; | |
} | |
} | |
} | |
for(i=0;i<ln;i++){ | |
if(i==0 && (op[i]>='a' || op[i]<='z')){ | |
op[i] -= 32; | |
}else if(op[i-1]==' ' && (op[i]>='a' || op[i]<='z')){ | |
op[i] -= 32; | |
} | |
} | |
} | |
int main(int argc,char *argv[]){ | |
char st[100]; | |
scanf("%99[^\n]s",st); | |
revStr(st); | |
printf("%s\n", op); | |
free(op); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment