error in assigning a path ?

This is a discussion on error in assigning a path ? within the C++ Programming forums, part of the General Programming Boards category; Dear all , I have this problem, I need to set the path of a file object from the user ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    40

    error in assigning a path ?

    Dear all , I have this problem, I need to set the path of a file object from the user using cin.getline, but I face a problem , please comment

    Code:
    int main(int argc, char *argv[])
    {  char file_name[40];
           if(argc == 1)
          {cout << "You can to pass in a file name to the program via the command line, "
               << " or type it down\n file : ";
             cin.getline(file_name,39);
               input_code.open(file_name);
     
    	  }
        else
            input_code.open(argv[1]);
    
    return 0;
    }

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Try using std::strings.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    40
    please if you can suggest something

  4. #4
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    What are your errors/problems?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    40
    I don't know what is exactly, I'm usinf VC++ , when I run the program every thing is okay , but when I type the file name and press enter , unhandled excpetion error appears. and assembly code also

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    I could not see a problem in the code provided. What is the rest?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #7
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Odd, it works for me in Dev-C++. I can output and everything.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    40
    >it works for me in Dev-C++. I can output and everything.

    what do you mean ?
    I rely have this problem !

  9. #9
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    I mean I can compile it, run it, and even modify it to ouput stuff into the file. I'm assuming that above your code you have this:
    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
     
    fstream input_code;
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  10. #10
    Registered User
    Join Date
    Nov 2006
    Posts
    40
    yes ,

    If I cancel the line
    Code:
      input_code.open(file_name);
    every thing wil be okay !

  11. #11
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Oh, oh:
    Code:
    input_code.open(file_name, ios::trunc);
    Maybe?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  12. #12
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    So what is your input? maybe it is longer than 39 characters?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  13. #13
    Registered User
    Join Date
    Nov 2006
    Posts
    40
    no , its only 12 character , and the file exixts

  14. #14
    Registered User
    Join Date
    Nov 2006
    Posts
    40
    still the same manutd

  15. #15
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Are you using a relative path or an absolute path? Try putting the file on your c drive and typing C:/Filename.txt when asked for the filename.

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

Similar Threads

  1. Shortest Path Maze Solver (Breadth Search Help)
    By Raskalnikov in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 07:41 PM
  2. clipping path
    By stanlvw in forum Windows Programming
    Replies: 0
    Last Post: 07-23-2008, 11:47 PM
  3. Can't figure out what keeps hanging up my program
    By shays in forum C Programming
    Replies: 7
    Last Post: 11-12-2007, 01:59 PM
  4. Path Finding Using Adjacency List.
    By DeepBlackMagic in forum C++ Programming
    Replies: 7
    Last Post: 05-16-2005, 02:34 PM
  5. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM

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