Skip to content

Instantly share code, notes, and snippets.

@maplebeats
Last active August 29, 2015 13:57
Show Gist options
  • Save maplebeats/9541813 to your computer and use it in GitHub Desktop.
Save maplebeats/9541813 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int slen(const char * string){
int i=0;
while(string[i]!='\0'){
i++;
}
return i+1;
}
char * scpy(const char * string){
char * p;
int len = slen(string);
p = (char *)malloc(len);
int i;
for(i=0; i<len; i++){
p[i] = string[i];
}
return p;
}
int main(int argc, char *argv[])
{
char * p;
p = scpy(argv[1]);
int i,len;
len = slen(p);
int tmp=len;
for(i=len;i>=0;i--){
if(p[i]==' ' || i == 0){
int j;
for(j=(i==0)?i:i+1;j<tmp;j++){
printf("%c",p[j]);
}
printf(" ");
tmp=i;
}
}
printf("\n");
free(p);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment