
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct product {
  char *code;
  int quantity;
};

struct product your_structure[10];
unsigned n = 0;

void splitup(char *s) {
  char *next_tok = strtok(s, " ");

  while (next_tok) {
    char *pcode = next_tok;
    char *qty = strtok(NULL, " ");
    next_tok = strtok(NULL, " ");

    if (qty == NULL) {
      fprintf(stderr, "Input string contained an odd number of tokens!\n");
      exit(1);
    }
    
    your_structure[n].code = pcode;
    your_structure[n].quantity = atoi(qty);
    n++;
  }
}

int main(int argc, char **argv)
{
  unsigned i;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s sample-string\n", argv[0]);
    return 1;
  } 
  
  splitup(argv[1]);
  for (i=0; i<n; i++) {
    printf("%u: %d of %s\n",
           i, your_structure[i].quantity, your_structure[i].code
           );
  }
  return 0;
}
