Opening a file with out using fopen()

This is a discussion on Opening a file with out using fopen() within the C Programming forums, part of the General Programming Boards category; I need to open/read/write/close a text file with out using file handling utilities. if any one have idea regarding this, ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    5

    Unhappy Opening a file with out using fopen()

    I need to open/read/write/close a text file with out using file handling utilities.

    if any one have idea regarding this, please let me know

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    Yes, you use the file handling functions which come with your operating system.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    If you use a unix environment you can use open() read() write() and close() to work with files. They are system calls.

    http://www.scit.wlv.ac.uk/~jphb/spos...alls/open.html

    Its something like working with binary files using stdio.h functions (fwrite() fread()).

    I don't know if this is useful to you!

  4. #4
    Registered User
    Join Date
    Jun 2007
    Posts
    5
    Yes it is possible by using system calls, but i should not use those system calls for file handling. whether it is possible by using pointers

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    Well you're S-O-L then if you can't use fopen() or open().
    At least, that covers all the easy ways.

    > whether it is possible by using pointers
    Files generally are not part of the memory map, so that's a no.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Files CAN be made part of the memory map using "mmap"(Linux/Unix) or "MapViewOfFile"(Widnows). But I believe both of these calls actually require a file to be opened first.

    The filesystem on the hard-disk is not part of the memory from the operating systems view of things, so it wouldn't be possible to use pointers without help from the OS to get the file's content into memory.

    --
    Mats

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Sorry, second post on the same topic:

    When you (satheesh) say that "I need to", where does this "need" come from? Whilst you can avoid using the "stdio" or similar functions in the C-library, there is really no way to not use the operating systems file-system functionality - that is part of how files work, and you can't really avoid it...

    --
    Mats

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    My guess it's another one of those pointless "do x without using the obvious" kind of homework assignments which some tutors seem to find amusing.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Maybe... redirection of i/o from the command line? Would that count?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Salem View Post
    My guess it's another one of those pointless "do x without using the obvious" kind of homework assignments which some tutors seem to find amusing.
    It is of cours good to excercise the "lateral thinking", but I agree that some tutors seem to like doing this more to show how clever they are than to actually add value for the student (the latter is why they are there, isn't it?).

    --
    Mats

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    you could just pass the FILE pointer if a module (such as a dll) already opened the file.

  12. #12
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    Half the dumb tricks that dumb tutors seem to like is the futile attempt to try and understand something like
    a = b++ * b++;

    Not only is such a thing undefined, the poor student has to figure out what brain damage the tutor suffered, then try and figure out how to get the same "answer" as the tutor.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  13. #13
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Salem View Post
    Not only is such a thing undefined, the poor student has to figure out what brain damage the tutor suffered, then try and figure out how to get the same "answer" as the tutor.
    Bad teaching is 100 times worse than no teaching at all. These silly things are punishments, not exercises.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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