printhead.h
Code:
#ifndef PRINTREAD_H_
#define PRINTREAD_H_
#define LINE 256
namespace ioline {
void outputLine(const char *line);
char * inputLine(void);
}
namespace tokens {
int tokenizer(char *str, char **array);
}
#endif /* PRINTREAD_H_ */
tokenizer.cpp
Code:
#include <iostream>
#include <cstring>
#include "printread.h"
namespace tokens {
int tokenizer(char *str, char **array);
int tokenizer(char *str, char **array)
{
int tokenCount;
const char *delims = " ,;:";
array[0] = strtok(str, delims);
tokenCount++;
while ( (++*array = strtok(NULL, delims)) != NULL)
{
tokenCount++;
}
return tokenCount;
}
}
token.cpp
Code:
template <typename T>
T **allocate(int rows, int cols)
{
T **array;
array = new T *[rows];
for (int i = 0; i < rows; i++)
{
array[i] = new T [cols];
}
return array;
}
else
{
int tokenCount;
char *line = new char [LINE];
line = ioline::inputLine();
ioline::outputLine(line);
array = alloacate(100, 100);
tokenCount = tokens::tokenizer(line, array);
std::cout << "Token count: " << tokenCount << std::endl;
std:: cout << "\nTokens:\n" << std::endl;
for(int i = 0; i < tokenCount; i++)
{
std::cout << array[i] << std::endl;
}
}
return 0;
The tokenizer.cpp is supposed to return an integer representing the token count. Somehow it does not.