File I/O:simple code problem

This is a discussion on File I/O:simple code problem within the C Programming forums, part of the General Programming Boards category; I'm actually beginning with C programming I use Dev C++ and I can't open the test file "baba.txt" using the ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    5

    File I/O:simple code problem

    I'm actually beginning with C programming
    I use Dev C++ and I can't open the test file "baba.txt" using the following program:

    #include <stdio.h>
    main()
    {
    FILE *fp;
    fp=fopen("c:\\baba.txt","r");
    system("pause");
    }

    Perhaps there are some protections... . fopen don't even return a 0...

    Could anyone help me ?
    Thanx in advance

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    What are you expecting fopen to do? How do you know it doesn't return 0?

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    5
    I just want to read a .txt file.I am expecting fopen to open it and show me what is inside... Am I wrong?

    It is written in the tutorial:"Note that it's possible for fopen to fail even if your program is perfectly correct: you might try to open a file specified by the user, and that file might not exist (or it might be write-protected). In those cases, fopen will return 0, the NULL pointer.".
    My program do not return 0...so I guess I am not concerned by those problems.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    You're not even checking the return value of fopen() so how do you know what it's returning? Opening a file doesn't magically show you what's inside. It just gives you the ability to read and/or write to it.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Jul 2006
    Posts
    5

    Lightbulb

    hmm...ok. Need a little printf in there...
    Thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  2. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

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