more file loading help

This is a discussion on more file loading help within the C++ Programming forums, part of the General Programming Boards category; Code: int fileIn( char *f ) { FILE *fd; if( ( fd = fopen( f, "r" ) ) ) { ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    77

    more file loading help

    Code:
    int fileIn( char *f ) {
      FILE *fd;
      if( ( fd = fopen( f, "r" ) ) ) {
        /* file exists */
        fclose( fd );
        return 1;
      } else {
        /* file doesn't exist */
        return 0;
      }
    }
    if i use this method to check to see if the file exists, when the file does exist what do i use to load the file contents into an array?
    Hooked On Phonics Didn't Work For Me!

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    fread()
    Google is your friend.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    It depends on what the file contains.

    Also, that's a rather C way of doing things, shouldn't you be using C++ io streams?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    77
    its going to be loading numbers and could i get an example of how to use it, i looked it up on that website from another post and ive searched this site but i dont understand how to use it.
    Hooked On Phonics Didn't Work For Me!

  5. #5
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    77
    alright i appreciate all the help, but i plain hate smart remarks. what is the purpose of a forum if all you get is links to here and there instead of actual help. sometimes it makes alot more sense when someone explains it to you rather than just looking on some guide that seems like something a computer generated.
    Hooked On Phonics Didn't Work For Me!

  7. #7
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    But the question has been asked and answered a million times. The function is well documented, there's no reason for anyone to have to explain it to you...

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    77
    if you dont want to give me an example, fine you dont have to. ill just ask some where else.
    Hooked On Phonics Didn't Work For Me!

  9. #9
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    hmm, if I were you I'd look into std::ifstream for input and std:fstream for output. They're much easier to work with (in my opinion, of course I've never tried FILE's)
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  10. #10
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    We already did this in your first thread.

    Your problems are stemming from the fact that every variable you use is global.

    I told you how to implement a solution using C++'s ifstream objects.


    if you dont want to give me an example, fine you dont have to. ill just ask some where else.
    Don't let the door hit you on the way out.

  11. #11
    Registered User
    Join Date
    Jan 2002
    Posts
    77
    hmm...imperito if you had even bother to check back on my last post you would have realize that i said that method didnt work either

    ive had no problems with those global variables till you started offering suggestions that just caused more problems.

    your all lazy, you cant type out one example, you have to just point to someone elses work that sometimes to hard to understand by someone that doesnt know what he is doing.

    i spent all day searching stuff on ways to accomplish what i wanted to accomplish i searched all over these boards and websites that i found on other posts which all led me to some site with stuff that made no sense.

    try offering some help instead of just pointing here or there to something else.
    Hooked On Phonics Didn't Work For Me!

  12. #12
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    I already posted a snippet of code in the other thread. I think your reason for not being able to adapt it was, oh let me think...

    for some reason
    Most of the people who stop by here aren't going to write your program for you. If you would post the problem code, and the errors you receive, then we could help you.

    ive had no problems with those global variables
    Except that the code you posted before DID have a problem, one which directly pertained to your misuse of global variables.

    If you want help with something, fine. But you need to be able to ask the question properly, not just say "X doesn't work someone do it for me"

  13. #13
    Registered User
    Join Date
    Jan 2002
    Posts
    77
    i didnt have any problems with my file untill i started getting help from you, all i wanted to do is to make it check to see if the file exists or not and you all throw these long responses back at me like im supposed to understand the whole thing, and it still didnt work it just gave me more errors.
    Hooked On Phonics Didn't Work For Me!

  14. #14
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Last resort plan, if you can't figure out what we're talking about:
    Buy a good book like "Sam's Teach Yourself C++ in 21 Days" and take a look at the file i/o section. Guaranteed, the book will teach you lots of useful stuff (not only file i/o), if you're smart enough to be doing C++ in the first place.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

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. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM

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