[ create a new paste ] login | about

Link: http://codepad.org/xMOw5MqA    [ raw code | output | fork ]

C, pasted on Mar 9:
#include<stdio.h>
#include<string.h>
#include<malloc.h>
char *str_rev(char s[]){
 static char *st = NULL;
 static char *l;
 int i = 0,c = 0;
 st = malloc((strlen(s) * sizeof(*s))+1);
 l = st;
 if(s == NULL){
  return "INVALID PARAMS"; // Added ;
 }
 for(i=0;s[i]!='\0';i++){
 ;
 }
 for(c=i-1;c >=0;c--){ // c = i -1
  *l++ = s[c];
 }
 *l = '\0';

 printf("\n s:%s \n l:%s \n",s,l);  
 //free(st);  not needed commented. 
 // return l; 
 
 return st; // return st instead of l 
}
int main(){
 char a[]="Angus Declan R"; // Added ;
 printf("\n %s \n",str_rev(a));
 return 0;
}


Output:
1
2
3
4
5

 s:Angus Declan R 
 l: 

 R nalceD sugnA 


Create a new paste based on this one


Comments: