Please help! Whenever it outputs the array, it prints garbage :( The purpose of my code is for it to go through a long text file, which has a conversion, like this.
2016-20-5: Bob: "Whats up!"
2016-20-5: Jerome: "Nothing bro!"
and for it to take this and break it up to like a format like this:
Person's Name: Bob Message Sent: Whats up! Date: 2016-20-5
(BTW there is a file called "char.txt"
and if I use a string
it works, but I cant use string
because some funcs only accept char*
)
Here is what I have so far, still trying to make it print out this:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
ifstream readchat;
readchat.open("chat.txt");
const int MAX = sizeof(readchat);
char line[MAX];
char *colon;
colon = strtok(line, ":");
while (!readchat.eof())
{
while (colon != NULL)
{
cout << line;
colon = strtok(NULL, ":");
}
}
system("pause");
return 0;
}