Unable to open a file for reading

This is a discussion on Unable to open a file for reading within the C Programming forums, part of the General Programming Boards category; Since it doesn't compile, I would say no. Also, str needs to be an array. You can't read 20 chars ...

  1. #16
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Since it doesn't compile, I would say no.

    Also, str needs to be an array. You can't read 20 chars into a buffer of size 0. BTW, if the file doesn't exist, why try to print the array?

  2. #17
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    printf("%s",str); should be inside the braces. same with fclose. Follow the program flow for if the file fails to open. str will be uninitialized.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-22-2008, 12:19 AM
  2. Unable to open include file SDL_audio.h
    By rraj.be in forum C Programming
    Replies: 2
    Last Post: 06-28-2008, 09:04 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 04:39 AM

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