Thread: File offset

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    File offset

    Hi!

    This is .pif file format:

    PIF Format
    Intel byte order

    OFFSET Count TYPE Description
    0000h 1 byte reserved
    0001h 1 byte Checksum
    0002h 30 char Title for the window
    0020h 1 word Maximum memory reserved for program
    0022h 1 word Minimum memory reserved for program
    0024h 63 char Path and filename of the program
    0063h 1 byte 0 - Do not close window on exit
    other - Close window on exit
    0064h 1 byte Default drive (0=A: ??)
    0065h 64 char Default startup directory
    00A5h 64 char Parameters for program
    00E5h 1 byte Initial screen mode, 0 equals mode 3 ?
    00E6h 1 byte Text pages to reserve for program
    00E7h 1 byte First interrupt used by program
    00E8h 1 byte Last interrupt used by program
    00E9h 1 byte Rows on screen
    00EAh 1 byte Columns on screen
    00EBh 1 byte X position of window
    00ECh 1 byte Y position of window
    00EDh 1 word System memory ?? whatever
    00EFh 64 char ?? Shared program path
    012Fh 64 char ?? Shared program data file
    016Fh 1 word Program flags

    Now I want to know how to write a code. For example I want that my program will display text for the title.

    Please, help.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    This

    fseek (file, N, SEEK_SET);

    places the filepointer at N bytes from the beginning. So when reading bytes from the file, the byte at that position will be read.

  3. #3
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    My code:

    int main()
    {
    FILE *fin;
    char file1[100], Title[30], *TitlePtr;

    clrscr();
    TitlePtr = Title;
    printf("Enter file name (*.pif): ");
    gets(file1);
    fin = fopen(file1, "rb");
    fseek(fin, 0x0002, SEEK_SET);
    fread(TitlePtr, sizeof(Title), 1, fin);
    printf("Title is \"%s\"", Title);
    return 0;
    }

    Ok, this is working. Well I get the title but I also get the file name.

    It looks like that:

    Title is "program filename.pif".

    How do I place the 0 at the end of that string?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    I'm not quite sure what you mean. You mean you want to split the string "program filename.pif" into "program" and "filename.pif"?

    In that case you could search in your string for the space and place the '\0' in that place.

    i = 0;
    while (Title [i++] != ' ');
    Title [i-1] = '\0';

    Why are you using TitlePtr and Title[30]? I think it's not necessary to use TitlePtr. In your call to fread you are using TitlePtr as a pointer to the array, but since Title is also a pointer, you could use Title instead of TitlePtr.
    Last edited by Shiro; 12-28-2001 at 12:14 PM.

  5. #5
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    No no, when the program prints out on the screen it looks something like that "title פ÷". This extra characters ( פ÷) are bugging me. How to get rid of them?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Hmm.. is this what you want?
    Code:
    int main() 
    { 
     FILE *fin; 
     char file1[100], Title[30]; 
     int i;
    
     clrscr(); 
     TitlePtr = Title; 
     printf("Enter file name (*.pif): "); 
     gets(file1); 
     fin = fopen(file1, "rb"); 
     fseek(fin, 0x0002, SEEK_SET); 
     fread(Title, sizeof(Title), 1, fin); 
     for (i = 0; i < 30; i++)
     {
      putchar (Title[i]);
     }
     return 0; 
    }
    Callou collei we'll code the way
    Of prime numbers and pings!

  7. #7
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Thanks! It's working now.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > How to get rid of them?
    Make sure you have a \0

    Code:
    char Title[31];
    fread(Title, sizeof(Title)-1, 1, fin);
    Title[30] = '\0';
    Now you should be able to use %s to print it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  2. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM