Thread: pointer in files

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    42

    pointer in files

    There is a large text file for my program to read in then output on the screen, is there anyway to point to a character ( including space ) in a text file?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> is there anyway to point to a character...
    Depends on what you mean my "point to". There's file position offsets and actual memory pointers.
    The file posistion is achieved using tellp() and tellg() members of ostream and istream respectively. The latter is achieved using memory mapped files, which is OS specific.

    gg

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    42
    I mean using a pointer variable to point to the 1st character in the file then keep on pointing till end of file.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    That would be the latter, memory mapped files, which is OS specific.

    gg

  5. #5
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    why couldn't you use a char * ?

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    In other words: what OS do you want to do this for?

    Perhaps a better question is: Why do you want to do this?

    gg

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> why couldn't you use a char * ?
    You certainly could.
    The most portable implementation of memory mapped files would be to simply allocate enough memory to hold the entire file and load the file into that memory.

    gg

  8. #8
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    I'm not sure why you would want to do this either, but isnt a text character universaly 1 byte?

    perhaps I dont fully understand what you mean Eavan. If I do, I dont see why you couldnt use just manipulate the file pointer with seekg and seekp along with char pointers.

  9. #9
    Banned borko_b's Avatar
    Join Date
    Jun 2002
    Location
    Well... I live in Bulgaria :)
    Posts
    100
    Not really ...
    The ASCII is one byte char...

    but the UNICODE char is two bytes:

    sizeof(wchar) == 2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-24-2008, 10:16 AM
  2. single File Pointer to Multiple Files
    By dayknight in forum C Programming
    Replies: 4
    Last Post: 09-16-2005, 12:49 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 01:09 PM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM