Results 1 to 10 of 10

Thread: Illegal operation

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    In this code used to read the contents of a text file I get a illegal operation at the very end right. Here the code

    #include <iostream.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>

    FILE *fp;

    class myclass{
    public:
    void openfile(char *path);
    };

    int main()
    {
    char retval;

    myclass s;

    cout <<"Enter a path to open \n";

    cin.getline(&retval, 30, '\n');

    s.openfile(&retval);

    system("pause");

    return 0;
    }

    void myclass:penfile(char *path)
    {
    char ch;

    if((fp = fopen(path, "r")) ==NULL)
    cout << "Cannot open file ERROR";

    ch = getc(fp);

    while (ch!=EOF){
    putchar(ch);
    ch = getc(fp);
    }
    fclose(fp);
    }

    *How do I embed code in a post? Thanks for your help.
    Matt

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You're getting an error because you haven't allocated a buffer for the string. You used char retval. That only has space for one character, you need something like char retval[31] in order to have space for 30 characters and the terminating NULL ('\0').

    To embed code use [code] [/code] tags.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Hyperactive Member Warmaster199's Avatar
    Join Date
    Aug 2000
    Location
    Canada
    Posts
    306

    Angry

    I've also got an Illegal Operation for one of my programs that I made in PowerC. It's supposed to do some calculation with floating-point. Whenever it gets to the floating-point part, I get an Illegal operation. I worked around it, but I would like to know what's wrong. Is it my compiler(PowerC), or my CPU(AMD486DX-2 80MHz)?

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What sort of FLOP was it?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Hyperactive Member Warmaster199's Avatar
    Join Date
    Aug 2000
    Location
    Canada
    Posts
    306
    This is the lines the illegal op happens:
    Code:
    int diskspace;   /*Bytes free got by getdiskfree(); */
    int diskfree;
    
    printf("You have %d kbytes left on you drive", diskfree);
    
    printf("Your drive is %f percent free", diskspace/diskfree*100); /* Line the illegal op occurs */
    Any ideas?

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    That's because printf is trying to interpret an int as a float since you didn't explicitly cast it.
    Try this:
    Code:
    printf("Your drive is %f percent free", ((float)(diskspace *100.0f) / (float)diskfree));
    Just out of interest, is PowerC 16-bit? Because a float is 4 bytes, and a 16-bit int is only 2. It's just a hunch...but I think that if you compiled it 32-bit there wouldn't be an error.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Hyperactive Member Warmaster199's Avatar
    Join Date
    Aug 2000
    Location
    Canada
    Posts
    306
    PowerC... I don't know if it's 16 bit. It's date says 1989-1995 by MIX software. It was around when the 386 and 486 was out so I'm guessing 32bit. I looked at the arguments for PowerC and there are 2 options for CPU - Compile for 80186 and Compile for 80286. It also says something about 8086 FPU stuff... Yeah. I think it is 16bit, now that I think of it. The good thing about PowerC is that it's very small. All the libraries/binaries/includes take up slightly more than a meg. You can pretty much take it anywhere where there's a PC with a floppy drive!

  8. #8
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Anything designed for DOS is 16-bit, although you could get 32-bit DOS extenders like DOS4GW which made it nearly a 32-bit environment.
    Harry.

    "From one thing, know ten thousand things."

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yeah. I think Watcom C/C++ came with a copy.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  10. #10
    Hyperactive Member Warmaster199's Avatar
    Join Date
    Aug 2000
    Location
    Canada
    Posts
    306

    Question:

    Is there any source code out there that any of you know about which will make DOS 32-bit?(Like DOS4GW) I've already got DOS4GW(for a game called C-Dogs), but source code could be interesting because then you can design something similar.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width