I am trying to split a string into tokens.
("file1.txt") contains this row: 12/04/2007,2111,35.23,35.23,35.20,35.22,15600,35.22
What I am trying to do now is to split this row up into tokens where the "," is the separator. The output that comes from this row will I put in ("file2.txt")
My code that I have tried to build look like this. I suppose I am on the right track but I cant find the ´wrong´ in the code.
Code:
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
int main()
{
char Rad[100];
char * Tecken;
//
ofstream Test;
Test.open ("file2.txt");
ifstream myfile ("file1.txt");
//
myfile >> Rad;
//
printf ("Splitting string \"%s\" into tokens:\n",Rad);
Tecken = strtok (Tecken,",");
while (Tecken != NULL)
{
printf ("%s\n",Tecken);
Tecken = strtok (NULL, ",");
Test << Tecken <<"\n";
}
Return 0;
}