Delimiter not working

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;
}

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";

Our professor stated that it is a tab delimited file so they should all be tabs.
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/
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


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











Last edited on
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.
Awesome that works actually! Thank you Much appreciated! I apologize this was a pretty easy issue I just am tired as hell. Thanks again!
No sweat. Good luck!
Topic archived. No new replies allowed.