solution_8_3_string_tokenizer.c
C Programming Language/solutions/intermediate/week8/solution_8_3_string_tokenizer.c
/**
* Solution 8.3: String Tokenizer
* Week 8 - Advanced Arrays and Strings
*
* Description: String tokenizer program
*/
#include <stdio.h>
#include <string.h>
void tokenizeString(char *str, char delimiter) {
char *token = strtok(str, &delimiter);
int count = 0;
printf("Tokens:\n");
while (token != NULL) {
count++;
printf("%d: %s\n", count, token);
token = strtok(NULL, &delimiter);
}
printf("Total tokens: %d\n", count);
}
int main() {
char str[200];
char delimiter;
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
// Remove newline character
str[strcspn(str, "\n")] = '\0';
printf("Enter delimiter: ");
scanf("%c", &delimiter);
tokenizeString(str, delimiter);
return 0;
}
Artigos relacionados
bitwise_operations_advanced.c
bitwise_operations_advanced.c — c source code from the C Programming Language learning materials (C Programming Language/additional/advanced_topics/bitwise_operations_advanced.c).
Ler artigo →huffman_coding_complete.c
huffman_coding_complete.c — c source code from the C Programming Language learning materials (C Programming Language/additional/advanced_topics/huffman_coding_complete.c).
Ler artigo →recursion_advanced.c
recursion_advanced.c — c source code from the C Programming Language learning materials (C Programming Language/additional/algorithms/recursion_advanced.c).
Ler artigo →sorting_algorithms_complete.c
sorting_algorithms_complete.c — c source code from the C Programming Language learning materials (C Programming Language/additional/algorithms/sorting_algorithms_complete.c).
Ler artigo →binary_trees_complete.c
binary_trees_complete.c — c source code from the C Programming Language learning materials (C Programming Language/additional/data_structures/binary_trees_complete.c).
Ler artigo →linked_lists_complete.c
linked_lists_complete.c — c source code from the C Programming Language learning materials (C Programming Language/additional/data_structures/linked_lists_complete.c).
Ler artigo →