Last active
October 6, 2020 16:20
-
-
Save 10maurycy10/f6a0ec88cd5e05801b083bc557e12dd5 to your computer and use it in GitHub Desktop.
an function to index into string
This file contains 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 <stdlib.h> | |
#include <stdio.h> | |
char* strindex(char* src,int start, int end) { | |
int len = end - start; | |
char* dst = malloc(len + 2); | |
for (int i = 0; i < (end - start) + 1; i++) | |
dst[i] = src[i + start]; | |
dst[len + 1] = 0; | |
return dst; | |
} | |
int main() { | |
char* x = "0123456789"; | |
char* substring = strindex(x,1,3); | |
printf("%s,%s\n", x, substring); | |
free(substring); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment