Advertisement
gihanchanaka

Untitled

May 9th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. /*Problem 31 GROUP 3*/
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. char* substr(char* str,int start,int end){
  7.     end++;
  8.     char* toReturn;
  9.     int len=strlen(str);
  10.     if(start<=0 || (start>(end-1) || (end-start)>len)  ){
  11.         toReturn=(char*)malloc(sizeof(char)*(100));
  12.         strcpy(toReturn,"Input valid start value and end value");
  13.         return toReturn;       
  14.     }
  15.  
  16.     toReturn=(char*)malloc(sizeof(char)*(end-start+2));
  17.     int x;
  18.     for(x=0;x<end-start;x++){
  19.         toReturn[x]=str[start-1+x];
  20.     }
  21.     toReturn[end-start+1]='\0';
  22.     return toReturn;
  23. }
  24.  
  25.  
  26. int main(){
  27.     printf("%s\n", substr("co222",1,0));
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement