/***************************************************************************
(c) Copyright 2002 Jeremy Russell, All Rights Reserved.
http://homepage.mac.com/hteric/Project4.pdf
****************************************************************************
File : rtoken.c
Author : Jeremy Russell
Date : November 14, 2002
Description : Write a program that inputs a line of text, tokenizes the
line with function strtok and outputs the token in reverse
order. Name this program 'rtoken.c' , submit source and
hard copy.y.
***************************************************************************/
#include <stdio.h>
#include <string.h>
#define SIZE 100
void reverse (char *);
void cleanToken(char *, int);
/***************************************************************************
Function : main
Author : Jeremy Russell
Date : November 14, 2002
Description : 'main' of rtoken.c
Arguments : void
Returns : Success or fail.
Notes :
See Also :
***************************************************************************/
int main ( void )
{
char string[SIZE];
printf("Input a string of tokens: ");
gets(string);
reverse(string);
return 0;
}
/***************************************************************************
Function : strtok
Author : Jeremy Russell
Date : November 14, 2002
Description : Takes a string, tokenizes it, and prints the tokens in the
reverse order.
Arguments : char *, int
Returns : void
Notes :
See Also :
***************************************************************************/
void reverse (char *tokens)
{
int count = 0;
char *strings[SIZE];
char delimiters[2] = {' ', '\t'};
while (strings[count] = strtok(tokens, delimiters)) {
tokens = NULL;
count++;
}
while ( count > 0 ) {
count--;
printf("%s ", strings[count]);
}
printf("\n");
}