DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Error Message Concerning Reading File From A Drive (http://www.daniweb.com/forums/thread15260.html)

cgre0205 Dec 8th, 2004 1:27 pm
Error Message Concerning Reading File From A Drive
 
I AM RUNNING A PROGRAM THAT DEALS WITH TEXT FILES IN NOTEPAD. I TYPE IN A FAKE SSN AND THE PROGRAM IS TO READ A LIST OF FILES FROM student course. I AM GETTING AN ERROR MESSAGE TELLING ME THAT PROGRAM CAN'T READ FILE. TWO EX OF SSN'S ARE 201235678 AND 123411234. THE FOLLOWING IS SOME OF THE PROGRAM

#include <iostream.h>
#include <iomanip.h>
#include <math.h>
#include <stdlib.h>
#include <fstream.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>


  struct student
  {
        long stud;
        char lname[12];
        char fname[8];
        char mi[1];
  };

 struct Books
        {
        char courseID[7];
        char title[50];
        double price;
        };

 struct title
        {
          char courseid[7];
          char  booktitle[50];
        };

 struct clas
        {
        long studid;
        char subjid[7];
        };

 int main () //Beginning of main
        {
          char chartest;

                                                //reading file
        ifstream infile("a:studentcourse.txt");

        clas *bol[200];
        title *pic[200];
        student *boc[200];
        Books *rec[200];
        long  ID;
        int count=0;
        int couter =0;
        int cou = 0;
        char *hold[7];

                                  //SET UP OUT STREAM FOR CURRENT OUTPUT
        cout    << setprecision (2)
                                << setiosflags (ios::fixed)
                                << setiosflags (ios::showpoint);




        cout<<"\n\n\nENTER STUDENT ID (social security number)\n";
        cin >> ID;

                                                                //reading file

        while (!infile.eof())
                {
                boc[count] = new student();
                infile>>boc[count]->stud>>boc[count]->lname>>boc[count]->fname
                                >>boc[count]->mi;
                count++;
                }

                  for(int i = 0; i < count ; i++)
                        {
                          long temp;
                       
                        if(temp == ID)
                        {
                          cout<<boc[i]->lname<<" "<<boc[i]->fname<<" "<<boc[i]->mi;
                        }
                  }

 cout<<"\n\n"<<setw(15)<<"Enter Y to continue or N to Cancel.\n\n\n";
 cin>>chartest;
        if(chartest == 'n' || chartest == 'N')
                {
                        getche();
                        clrscr();
                        return 0;
                }//endif

 cout<<"\n\n\nStudent ID No:"<<setw(25)<<ID;"\n\n";

 cout<<"\n\nYou are enrolled in the following classes:\n";

                                            // reading file
        ifstream infile_fil ("a:studentcourse.txt");

        if (infile_fil.fail())
          {
                cout<<"\nThere is a problem locating the input file a:studentcourse.txt.\n";
                cout<<"\nCheck that input file is on the correct drive\n";
                cout<<"\nand that the name of the file is spelled correctly.";
                exit (1) ;

                }

I WOULD APPRECIATE IF I COULD GET A RESPONSE AS SOON AS POSSIBLE

Dave Sinkula Dec 8th, 2004 1:56 pm
Re: Error Message Concerning Reading File From A Drive
 
It might be a little easier to look at your code if it were enclosed within [CODE][/CODE] tags.

Hmmm. You open a file and never close it, then you open it.

alc6379 Dec 8th, 2004 6:31 pm
Re: Error Message Concerning Reading File From A Drive
 
Quote:

Originally Posted by Dave Sinkula
It might be a little easier to look at your code if it were enclosed within [CODE][/CODE] tags.

Hmmm. You open a file and never close it, then you open it.

...I went ahead and added the tags, but what's the deal with ALL CAPS LATELY?

Dave Sinkula Dec 8th, 2004 6:39 pm
Re: Error Message Concerning Reading File From A Drive
 
>what's the deal with ALL CAPS LATELY?

If you mean [CODE][/CODE], that's how they show up when you hit the button. And that's how they sit in my template text file. Plus sometimes it needs to be said a little louder.

If you meant this post, that was an attempt at sarcasm.

alc6379 Dec 8th, 2004 6:44 pm
Re: Error Message Concerning Reading File From A Drive
 
Quote:

Originally Posted by Dave Sinkula
>what's the deal with ALL CAPS LATELY?

If you mean [CODE][/CODE], that's how they show up when you hit the button. And that's how they sit in my template text file. Plus sometimes it needs to be said a little louder.

If you meant this post, that was an attempt at sarcasm.

Oh... no no no... not you... I mean everyone else. Your capitalization habits are sane, AFAICT. ;)


All times are GMT -4. The time now is 10:15 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC