Just need your quick advice/opinion

This is a discussion on Just need your quick advice/opinion within the C++ Programming forums, part of the General Programming Boards category; driver Code: #include <string.h> #include <iostream.h> #include <fstream.h> #include <stdlib.h> #include "building.h" void main() { building b[12]; char userLocA[10]; char ...

  1. #16
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Arrow driver

    driver

    Code:
    #include <string.h>
    #include <iostream.h>
    #include <fstream.h>
    #include <stdlib.h>
    #include "building.h"
    
    
    void main()
    {
    
      building b[12];
      char userLocA[10];
      char userLocB[10];
      ifstream input_file;
    
      input_file.open("paths.txt");
      if(input_file.fail())
        {
          cout <<"Input file could not be opened.\n";
          exit(1);
        }
    
      for(int index=0; index<12; index++)
        {
          b[index].intLocationOne(input_file.getline());
          b[index].intLocationTwo(input_file.getline());
          b[index].setPath(input_file.getline());
        }
      cout <<"\nCAMPUS DIRECTIONS!\n";
      cout <<"Here are your building choices:\n";
      cout <<"Student Center, Weaver, CTLM, and Coolbaugh\n";
      cout <<"Where are you now?";
      cin >> userLocA;
      cout <<"Where do you want to go?";
      cin >> userLocB;
      
      for (int 12)
        {
          if ((strcmp(userLocA, r[index].getLocation1()))&&(strcmp(userLocB, r[index.getLocation2()))))
    	{
    	  cout << "Here are your directions:" << b[index].getPath();
    	  break;
    	}
        }
      
      
    
    }

  2. #17
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Arrow Driver File

    Ok I got my header and definition files finally worked out and now I just need help with the driver here is the driver.

    Code:
    #include <string.h>
    #include <iostream.h>
    #include <fstream.h>
    #include <stdlib.h>
    #include "building.h"
    
    
    void main()
    {
    
      building b[12];
      char userLocA[10];
      char userLocB[10];
      ifstream input_file;
    
      input_file.open("paths.txt");
      if(input_file.fail())
        {
          cout <<"Input file could not be opened.\n";
          exit(1);
        }
    
      for(int index=0; index<12; index++)
        {
          b[index].intLocationOne(input_file.getline(getPath,120));
          b[index].intLocationTwo(input_file.getline());
          b[index].setPath(input_file.getline());
        }
      cout <<"\nCAMPUS DIRECTIONS!\n";
      cout <<"Here are your building choices:\n";
      cout <<"Student Center, Weaver, CTLM, and Coolbaugh\n";
      cout <<"Where are you now?";
      cin >> userLocA;
      cout <<"Where do you want to go?";
      cin >> userLocB;
      
      for (int i=0; index<12; i++)
        {
          if ((strcmp(userLocA, b[index].getLocationOne()))&&(strcmp(userLocB, b[index.getLocationTwo()))))
    	
    	  cout << "Here are your directions:" << b[index].getPath();
    	  break;
    	
        }
      
      
    
    }

  3. #18
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    your driver looks good as far as the logic goes (although you might want to add a cout << "cannot find buildings" or something if none of the entries match.

    what you need to do now is check syntax. the getline function does not return the line, it puts the line into the variable passed...

    getline(line); // the data read in will be stored in 'line'

    you may need to use a temp variable to read the line into so you can pass it to your 'set' functions.

  4. #19
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Arrow ?

    I can get this to compile but i am getting a segmentation fault error what do you think about the getline fxn now?

    Code:
    //Name: Joseph Valenzuela
    //Date: 04/28/03
    //Purpose: The driver for project2
    
    #include <string.h>
    #include <iostream.h>
    #include <fstream.h>
    #include <stdlib.h>
    #include "building.h"
    
    
    void main()
    {
    
      building b[12];
      char userLocA[10];
      char userLocB[10];
      ifstream input_file;
    
      input_file.open("paths.txt");
      if(input_file.fail())
        {
          cout <<"Input file could not be opened.\n";
          exit(1);
        }
      char* buffer;
      for(int index=0; index<12; index++)
        {
          input_file.getline(buffer,255);
          
          b[index].intLocationOne(buffer);
          input_file.getline(buffer,255);
          b[index].intLocationTwo(buffer);
          input_file.getline(buffer,255);
          b[index].setPath(buffer);
          
         
        }
      cout <<"\nCAMPUS DIRECTIONS!\n";
      cout <<"Here are your building choices:\n";
      cout <<"Student Center, Weaver, CTLM, and Coolbaugh\n";
      cout <<"Where are you now?";
      cin >> userLocA;
      cout <<"Where do you want to go?";
      cin >> userLocB;
      
      /*
      for (int i=0; index<12; i++)
        {
          if ((strcmp(userLocA, b[index].getLocationOne()))&&(strcmp(userLocB, b[index.getLocationTwo()))))
    	
    	  cout << "Here are your directions:" << b[index].getPath();
    	  break;
    	
        }
      */
      
    
    }

  5. #20
    Registered User
    Join Date
    Feb 2003
    Posts
    29
    What do you think? I have to turn this in by midnight and its getting nowhere. Do you have AOL instant messanger or yahoo or MSN or something, I could really use some one on one I am so close.

  6. #21
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    the getline() looks good. you just have to get the comparing right (which i noticed you have another thread for, that should come together ok) i would give you my icq and help one on one but im on my way out and wont be home untill later tonight. srry. im sure the others around here can give you a hand.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 08:48 PM
  2. Do you know...
    By davejigsaw in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 11:33 AM
  3. recursive quick sort - stack overflow
    By Micko in forum C Programming
    Replies: 9
    Last Post: 01-01-2005, 05:51 PM
  4. Questions on basic Quick Sort
    By Weng in forum C++ Programming
    Replies: 4
    Last Post: 12-16-2003, 10:06 AM
  5. Replies: 0
    Last Post: 04-30-2002, 08:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21