View Single Post
Old Feb 14th, 2007, 4:30 AM   #3
rwm
Professional Programmer
 
Join Date: Jan 2007
Location: Cape Town
Posts: 291
Rep Power: 2 rwm is on a distinguished road
hi,

well i decided that writing a GetToken function would be a much better way to parse the file:

#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;

enum TokenType {NUL,DEFORMER,COLON,VALUE};

//get token
TokenType GetToken(char *p,char token[100]) {

	unsigned int index = 0;

	while(*p != ' ' && *p != '\n') {

		token[index] = *p;

		*p++; index++;

	}

	token[index] = '\0';

	//get token type
	if(!strcmp("deformer",token)) {

		//got a deformer
		return DEFORMER;

	}

	return NUL;

}

int main() {

	char *p = "deformer is me";
	char token[100];

	if(GetToken(p,token) == DEFORMER) {

		cout << "got a deformer";

	}

	cout << "\n\npress a key to exit...";
	while(!kbhit()) ;

	return 0;

}

it works, but the problem is i dont know how I can get a pointer to the file contents?

any suggestions?

hope someone can help me out!

thx!
rwm is offline   Reply With Quote