Friday, October 10, 2014

Parsing words through strtok

Here's how to parse words through strtok().

#include "stdio.h"
#include "string.h"

int main() {
  char line[100];
  char *pch;

  while (fgets(line, 100, stdin)) {
    pch = strtok(line, " \t\n");
    while (pch) {
      printf("B%sE\n", pch);
      pch = strtok(NULL, " \t\n");
    }
  }

  return 0;
}


No comments:

Post a Comment