Am I writing a programme intended to read a text file and format the contents. The text file is one long line, and should be formatted such that a new line is used instead of a ',' in the text.
/* strtok example */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
getline (myfile,line);
char str[] = line;
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str,",");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, ",");
}
int a ;
cin >> a;
return 0;
}
Right now I am getting 17 C:\Dev-Cpp\Parser\Main.cpp initializer fails to determine size of `str'
I can't say that I understand this error or now to fix it. Any advice would be helpful. Clearly I am very new to this and am trying to grasp the basics while writing things I find useful.