Thread: I need Help writing a loop with an incrament

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    4

    I need Help writing a loop with an incrament

    Hello I been working on this code but I cant get it too loop back untill all values in this file are printed out on the screen. The code will print out just the "cout" statements only one time on screen but will not produce the values. Also it wont loop back and give me the results of the whole list. Also there is a warning on thecompiliar that says... 'rec' is assigned a value that is never used. Here is the code any help will be greatly appreciated. Thank you

    Code:
    void main() 
    { 
       int z; 
       cout<<"test"<<endl; 
       AcademicRec(); 
       cin>>z; 
    } 
    
    
    
    void AcademicRec()       //Reading the AcademicRec's File 
    { 
    
       ifstream acctFile ("Accounts1.dat");   // This is the accounts database file 
    
       char line[200]; 
       char rec = 0; 
       int z; 
    while(!acctFile.eof()) 
    { 
         acctFile.getline(line,200); 
         if(line[0]==rec) 
         { 
    
                acctFile.seekg((acctFile.tellg()-strlen(line)),ios::beg); //seek to the begginning of the line 
                acctFile.getline(line,200,' '); //get everything up to the space 
                cout << "Social Security #: " << line << endl; 
                acctFile.getline(line,200,' '); 
                cout << "First Name: " << line << endl; 
                acctFile.getline(line,200,' '); //get everything up to the space 
                cout << "Last Name: " << line << endl; 
                acctFile.getline(line,200,' '); 
                cout << "Phone Number: " << line << endl; 
                acctFile.getline(line,200,' '); //get everything up to the space 
                cout << "Home Street: " << line << endl; 
                acctFile.getline(line,200,' '); 
                cout << "Home Town: " << line << endl; 
                acctFile.getline(line,200); //get everything up to the space 
                cout << "State: " << line << endl; 
    
         } 
    } 
        rec++; 
        cin >>z; 
    }

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    5
    Quote Originally Posted by sell682
    Also there is a warning on thecompiliar that says... 'rec' is assigned a value that is never used.
    Code:
       char rec = 0; 
        rec++;
    I may be wrong but can you increment a char?

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    > I may be wrong but can you increment a char?

    Yes you can, it is just like any other number only that its 8-bit. Integers are normally 32-bits (16-bits on older machines, 64-bits on cutting-edge computers).

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    5
    Thanks Speedy5 and sorry sell682.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. Visual Studio Express / Windows SDK?
    By cyberfish in forum C++ Programming
    Replies: 23
    Last Post: 01-22-2009, 02:13 AM
  3. Replies: 8
    Last Post: 12-01-2008, 10:09 AM
  4. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-31-2006, 12:59 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM