Delimiter not working

Apr 7, 2018 at 1:42am
For a project I have to pass data from a file into an HTML code. The delimiter is not working (\t) instead of selecting all data between tabs, it selects only some data in between tabs and messes up the whole form. Any help would be appreciated.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71


#include <iostream>
#include <fstream>
using namespace std;

   string Cnumber ="Course Number";
   string Cname ="Course Name";
   string date1 ="Date2";
   string date2 ="Date1";
   string times ="Times";
   string Dnumber ="Number of Days"; 

void head();
void table();
void foot();

int main()
{
  ifstream fin;
   ofstream fout;
   
      
   
   fin.open("Schedule.txt");
   fout.open("site.html");
   
   fout << "<DOCTYPE! HTML>" << endl;
   fout << "<html>" << endl;
   fout << "\t" << "<head>" << endl;
   fout << "\t" << "</head>" << endl;
   fout << "\t" << "<body>" << endl;
   fout << "\t" << "\t" << "<table border = '2' bordercolor = 'black' bgcolor = 'lightblue'>>" << endl;
   fout << "\t" << "\t" << "\t" << endl;
   fout << "\t" << "\t" << "\t" << "<tr>" << endl;

   fout << "\t" << "\t" << "\t" << "<td>" << "Course Number" << "</td>" << endl;
   fout << "\t" << "\t" << "\t" << "<td>" << "Course Name" << "</td>" << endl;
   fout << "\t" << "\t" << "\t" << "<td>" << "Start" << "</td>" << endl;
   fout << "\t" << "\t" << "\t" << "<td>" << "Finish" << "</td>" << endl;
   fout << "\t" << "\t" << "\t" << "<td>" << "Times" << "</td>" << endl;
   fout << "\t" << "\t" << "\t" << "<td>" << "Number of Days" << "</td>" << endl;
   while(!fin.eof())
   {
      getline(fin, Cnumber, '\t');
      fout << "\t" << "\t" << "\t" << "<tr>" << endl;
      fout << "\t" << "\t" << "\t" << "<td>" << Cnumber << "</td>";
      getline(fin, Cname, '\t');
      fout << "\t" << "\t" << "\t" << "<td>" << Cname << "</td>";
      getline(fin, date1, '\t');
      fout << "\t" << "\t" << "\t" << "<td>" << date1 << "</td>";
      getline(fin, date2, '\t');
      fout << "\t" << "\t" << "\t" << "<td>" << date2 << "</td>";
      getline(fin, times, '\t');
      fout << "\t" << "\t" << "\t" << "<td>" << times << "</td>";
      getline(fin, Dnumber, '\t');
      fout << "\t" << "\t" << "\t" << "<td>" << Dnumber << "</td>"<< endl;


   }
   fout << "\t" << "\t" << "\t" << "</tr>" << endl;
   fout << "\t" << "\t" << "</table>" << endl;
   fout << "\t" << "</body>" << endl;
   fout << "</html>" << endl;


   
   return 0;
}

Apr 7, 2018 at 2:01am
Check the input file. Are all the "tabs" actually tabs? Are they all single tabs? Maybe look at it in a hex editor.

BTW, we would normally write this
 
   fout << "\t" << "\t" << "\t" << "<td>" << "Course Number" << "</td>" << endl;

more like this
 
   fout << "\t\t\t<td>Course Number</td>\n";

Apr 7, 2018 at 2:31am
Our professor stated that it is a tab delimited file so they should all be tabs.
Apr 7, 2018 at 2:49am
Well, if they really are single tabs with a single newline at the end of the line then it should work.

What operating system are you using?

Upload the input file here and post the link: http://www.tinyupload.com/
Apr 7, 2018 at 3:06am
Apr 7, 2018 at 3:16am
Okay. So it's all single tabs and the line endings are 0x0d 0x0a (Windows line endings), except that the last newline combo is missing.

But there are 8 fields per record whereas you are only reading 6. That's why it gets out of sync. You need to reread your spec to determine what all the fields are. There seems to be 3 fields that have to do with time but you are only reading one.

I asked you what operating system you were using. I.e., Windows? Linux? Mac?
Last edited on Apr 7, 2018 at 3:17am
Apr 7, 2018 at 3:31am


I am using windows. So how would I delimit the file? It shouldn't be too complicated.











Last edited on Apr 7, 2018 at 3:32am
Apr 7, 2018 at 3:40am
It should be simple. But you have the spec, not me. Reread it. There are a total of 8 fields, not 6.

The problem is that there are two more fields between Times and Number of Days. There are two times and a time zone. So the last 4 fields look like this:
8:30 AM<TAB>4:30 PM<TAB>Eastern Time<TAB>5<NEWLINE>

Note that you need to use a delimiter of \n for the last field.
Apr 7, 2018 at 3:41am
Awesome that works actually! Thank you Much appreciated! I apologize this was a pretty easy issue I just am tired as hell. Thanks again!
Apr 7, 2018 at 3:56am
No sweat. Good luck!
Topic archived. No new replies allowed.