Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Problem 31 GROUP 3*/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char* substr(char* str,int start,int end){
- end++;
- char* toReturn;
- int len=strlen(str);
- if(start<=0 || (start>(end-1) || (end-start)>len) ){
- toReturn=(char*)malloc(sizeof(char)*(100));
- strcpy(toReturn,"Input valid start value and end value");
- return toReturn;
- }
- toReturn=(char*)malloc(sizeof(char)*(end-start+2));
- int x;
- for(x=0;x<end-start;x++){
- toReturn[x]=str[start-1+x];
- }
- toReturn[end-start+1]='\0';
- return toReturn;
- }
- int main(){
- printf("%s\n", substr("co222",1,0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement