I need help in file handling.
The problem is...
In a text file.. consists of (5) five student load with their...(subject,description,units,teacher,room,time, and day)..
I did the first student load.. but I could hardly proceed on the next student loads..
I easily did this in Java.. but on C++ i could hardly get the code..
Any help is very appreciated..
the text file looks like this:
[IMG]http://i164.photobucket.com/albums/u4/kenzo1588/notepad.jpg[/IMG]
my current output right now is:
[IMG]http://i164.photobucket.com/albums/u4/kenzo1588/SPL.jpg[/IMG]
my current code right now:
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <stdio.h>
#include <conio.h>
#include <iomanip>
int main()
{
using std::atoi;
std::ifstream File("NEW.txt");
int ctr;
static char subj[150];
int sum = 0;
char desc[150];
char unit[150];
char tch[150];
char rm[150];
char tym[150];
char day[150];
char sb[15] = "Subject";
char ds[12] = "Description";
char un[6] = "Units";
char tc[8] = "Teacher";
char room[5] = "Room";
char tm[5] = "Time";
char dy[4] = "Day";
printf("\n-------------------------------------------------------------------------------------------------\n");
printf("%-12s%-20s%-7s%-14s%-11s%-18s%-18s", sb,ds,un,tc,room,tm,dy);
printf("\n-------------------------------------------------------------------------------------------------\n");
for(ctr = 0; ctr<5;ctr++)
{
File.getline(subj,20,',');
File.getline(desc,32,',');
File.getline(unit,5,',');
int i = atoi(unit);
File.getline(tch,30,',');
File.getline(rm,20,',');
File.getline(tym,20,',');
File.getline(day,15,',');
printf("%-13s", subj);
printf("%-20s", desc);
printf("%-7d", i);
printf("%-14s", tch);
printf("%-11s", rm);
printf("%-18s", tym);
printf("%-18s", day);
sum = sum + i;
}
printf("\n-------------------------------------------------------------------------------------------------\n");
printf("There are total of %d subjects.\n", ctr);
printf("There are total of %d units.\n", sum);
File.close();
getche();
return 0;
}