Skip to content

Instantly share code, notes, and snippets.

@10maurycy10
Last active October 6, 2020 16:20
Show Gist options
  • Save 10maurycy10/f6a0ec88cd5e05801b083bc557e12dd5 to your computer and use it in GitHub Desktop.
Save 10maurycy10/f6a0ec88cd5e05801b083bc557e12dd5 to your computer and use it in GitHub Desktop.
an function to index into string
#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