letting the user type in the filename.

This is a discussion on letting the user type in the filename. within the C++ Programming forums, part of the General Programming Boards category; well, I know this is pretty fundmental but I'm getting debug assertion errors and I don't understand why. The user ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    16

    letting the user type in the filename.

    well, I know this is pretty fundmental but I'm getting debug assertion errors and I don't understand why.
    The user enters a file name, I use getline to extract it.. then in my read file fuction , to which I've passed a pointer to the filename, I call it. Sounds simple but I can't seem to get it. Please help.
    Here is what I did:

    [code] .

    cout<< "Please enter the name of the maze file you want to read, or (q) to quit.\n" << endl;
    cout<< "(a) maze1.txt\n(b) maze2.txt\n(c) maze3.txt\n"<< endl;
    cin.getline (filename, 10);

    void Read_file (char m_array[][40], int *columns, int *rows, Curr_pos &start, char *filename)
    {
    int a = 0;
    int b = 0;
    int f = 0;
    char temp;
    char *pfilename;

    pfilename = filename;

    FILE *inp; //A pointer to the input file.
    // FILE *outp; // A pointer to the output file.

    inp = fopen("pfilename","r"); // Opens the input file.
    // outp = fopen("copy.txt","w"); // Writes into an output file.

    fscanf(inp,"%d %d", rows, columns); ** this is where the problem is.The rest of the code actually works fine. I'm pretty certain of that.

    for ( a = 0; a < *rows; a++)
    {
    for ( b = 0; b < *columns; b++)
    {
    do {
    fscanf(inp,"%c", &temp);
    } while ( temp ==' ' || temp =='\n');

    m_array[a][b] = temp;

    if ( m_array[a][b] == 'E')
    {
    printf("Then coordinates for the entrance are: %d,%d\n", a,b);
    start.row = a;
    start.col = b;
    }
    if (m_array[a][b] == 'X')
    {
    printf ("The coordinates for the exit are: %d,%d\n", a, b);
    }
    }
    }

    fclose (inp);
    }
    /[code] .
    Last edited by doampofo; 04-16-2003 at 10:24 PM.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    you could just store it in a string, pass the string as the parameter, and use .c_str() if ifstream.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    inp = fopen("pfilename","r");
    Anything in quotes is a string. That is your problem.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    16

    Lightbulb Thanks

    thanks, that worked. I wonder how people like you get this good.... I guess it's just practice , paractice....I've got a long way to go then.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

    Re: Thanks

    Originally posted by doampofo
    thanks, that worked. I wonder how people like you get this good.... I guess it's just practice , paractice....I've got a long way to go then.
    it is practice. just keep coding and keep learning; you'll get better.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  4. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM
  5. header file bringing errors?
    By bluehead in forum Windows Programming
    Replies: 4
    Last Post: 08-19-2003, 01:51 PM

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