major problemz!!

This is a discussion on major problemz!! within the C++ Programming forums, part of the General Programming Boards category; Hi~ I am using the fstream modes to open and read files. I want to read characters from the files ...

  1. #1
    Unregistered
    Guest

    major problemz!!

    Hi~

    I am using the fstream modes to open and read files. I want to read characters from the files and assign them to different variables so I can store them and display them later. Is there any way to do this?? I need this really urgent ..I tried many ways and I keep getting gerenal protection error ..!! Please helP~

    ~secyw~

  2. #2
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    You could try to store the characters into an array. That would be the way I would do it.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Post your code.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Ok Adrian, What does "Med venlig hilsen" mean? I asume it is Jerman??
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> Ok Adrian, What does "Med venlig hilsen" mean?

    Roughly, "With friendly greetings".

    >>> I asume it is Jerman??

    You mean German? No. Look at my "Location:" line over to the left!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    FYI:

    "Mit freundlichen Gruessen" or short "mfg" is the german term for it
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  7. #7
    Unregistered
    Guest
    Hi~
    THis is my code and it keeps ..stating ..general protection error.

    #include <fstream.h>
    #include <stdlib.h>
    #include <string.h>
    #include <io.h> // Header file that includes the 'EOF' function

    void main ()
    {
    ifstream new_name; // Declares input stream

    new_name.open ("c:/files/names.txt", ios::in); // Opens the textfile

    if (!new_name) // Checks to see if file is in the disk
    {
    cout << "Error opening file.\n"; // Displays information on to the screen
    exit(1); // Exits the program
    }

    char *name [100]; // Declares the variable as type char with maximum of 80 characters
    char *lname [100];
    int age [20];
    int a =0;

    while (new_name)
    {

    new_name >> name [a] >> lname [a] >> age [a];
    new_name.ignore(131,'\n'); /* skip up to and including the first newline
    character it encounters or to skip 133 characters (maximum amount of characters in 1 line)*/
    a++;
    eof(1); // Ends the loop when it is at end of file
    }

    new_name.close(); // Closes the file
    }

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    This doesn't crash, but I'm not sure it is doing what you want, you don't seem to be doing anything with the results...

    .
    .
    .

    char name [100]; // Declares the variable as type char with maximum of 80 characters
    char lname [100];
    int age [20];
    int a =0;

    while (new_name)
    {

    new_name >> name >> lname >> age [a];
    new_name.ignore(131,'\n'); /* skip up to and including the first newline
    character it encounters or to skip 133 characters (maximum amount of characters in 1 line)*/
    a++;
    eof(1); // Ends the loop when it is at end of file
    }
    .
    .
    .
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Jerman oh my I can not believe I messed that up! I must have been tired! I usualy work 10.5 hours a night(8:15pm - 6:45am) and then sit at my computer for another hour before I go to bed. My bad. And I didn't even notice Denmark. Thanks for telling me though.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

Popular pages Recent additions subscribe to a feed

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