Created
August 26, 2020 13:28
-
-
Save Silva97/6c87df2cb7fce807e3d25e90dc9e513d to your computer and use it in GitHub Desktop.
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 <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