[ create a new paste ] login | about

Link: http://codepad.org/RCCsTYC2    [ raw code | output | fork ]

anmartex - C, pasted on Feb 22:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdbool.h>
 
//----------------------------------------------//
bool GetWord(const char text[], const char** begin, const char** end)
{
   for (; *text && !isalnum(*text); ++text);
 
   *begin = text;
 
   for (; *text && isalnum(*text); ++text);
 
   *end = text;
 
   return *begin != *end;
}
//----------------------------------------------//
void PrintWords(const char text[])
{
   const char* begin;
   const char* end;
 
   while (GetWord(text, &begin, &end))
   {
      fprintf(stdout, "[%.*s]\n", end - begin, begin);
      text = end;
   }
}
//----------------------------------------------//
 
#define TEXT_SIZE 256
 
int main(int argc, const char* argv[])
{
   //fprintf(stdout, "input string: ");
 
   char text[TEXT_SIZE] = "Hello World. I Am Student!";
 
   //fgets(text, TEXT_SIZE, stdin);
 
   PrintWords(text);
 
   return EXIT_SUCCESS;
}


Output:
1
2
3
4
5
[Hello]
[World]
[I]
[Am]
[Student]


Create a new paste based on this one


Comments: