fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main() {
  5. char input[100]; // To store the entire input string
  6. char items[100][10]; // Array to store mixed items (up to 100 items, max 9 chars + null terminator)
  7. int count = 0; // Counter for items
  8.  
  9. // Prompt the user for input
  10. printf("Enter the array in format [1a,b2,33,ABC,af]: ");
  11. scanf("%[^\n]s", input); // Read the entire line of input.
  12.  
  13. // Tokenizing the input string
  14. char *token = strtok(input, "[,] "); // Split by commas and brackets
  15.  
  16. // Storing the tokens into the items array
  17. while (token != NULL) {
  18. strcpy(items[count], token); // Copy the token into the items array
  19. count++; // Increase the count of items
  20. token = strtok(NULL, "[,] "); // Get the next token
  21. }
  22.  
  23. // Output the results
  24. printf("The items are:\n");
  25. for (int i = 0; i < count; i++) {
  26. printf("%s\n", items[i]);
  27. }
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Enter the array in format [1a,b2,33,ABC,af]: The items are:
�o�