//Youtube: https://[Log in to view URL]
//myCompiler https://[Log in to view URL]
#include <stdio.h>
#include <string.h>
int main() {
// This is the string we want to split into separate cryptocurrencies
// Some names are separated by a comma ',' or a tab '\t'
char input[] = "BTC,ETH\tDOGE,XRP";
char *token; // This will hold one cryptocurrency at a time
char delimiters[] = ",\t"; // These are the characters that separate the names
char last_separator = '\0'; // This will remember the character that separated the last token
// First call to strtok:
// Give the string and the delimiters.
// It will find the first token (everything before the first comma or tab)
// It replaces the comma or tab with '\0' to mark the end of the token
// Internally, strtok remembers where it stopped for the next call
token = strtok(input, delimiters);
// Keep looping until strtok says there are no more tokens
while (token != NULL) {
// Print the current token (cryptocurrency symbol)
printf("Crypto: %s\n", token);
// Look at the character right after the token in the original string
// This tells us which separator was used (comma or tab)
// The '\0' marks the end of the token, but strtok remembers where to continue
char *character_after_token = token + strlen(token);
// Only store the separator if we are not at the end of the string
if (*character_after_token != '\0') {
last_separator = *character_after_token; // Save the separator that was after this token
printf("Separator found: '%c'\n", last_separator);
}
// Next call to strtok:
// Pass NULL to continue from where we left off
// This finds the next token without starting over
token = strtok(NULL, delimiters);
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: