Skip to content

Instantly share code, notes, and snippets.

@Silva97
Created August 26, 2020 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Silva97/6c87df2cb7fce807e3d25e90dc9e513d to your computer and use it in GitHub Desktop.
Save Silva97/6c87df2cb7fce807e3d25e90dc9e513d to your computer and use it in GitHub Desktop.
#include <stdio.h>
// Example of code in C to get substrings
char *substr(char *dest, char *src, int start, int end)
{
char *start_address = dest;
for (src = src + start; *src && end > 0; dest++, src++, end--) {
*dest = *src;
}
*dest = '\0';
return start_address;
}
int main(void)
{
char buff[32] = "Dados anteriores";
char test[] = "Eu sou um teste";
puts( substr(buff, test, 3, 3) ); // "sou"
puts( substr(buff, test, 10, 30) ); // "teste"
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment