Thread: a bit of help with fgets

  1. #1

    Angry a bit of help with fgets

    ive used the fgets command to get a string from a file.
    ie: fgets(filename, 256, fptr);

    the string is actually a filename.
    im trying to get information from the inode about that file so i used stat.
    ie: stat(filename, &file_info);

    its returning incorrect values, so im guessing it has something to do with the newline character retained when using fgets.

    any ideas on how i could get around this would be great.


  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    If it is the newline char, just blat over it with a \0. Something like

    >filename[strlen(filename)-1)] = '\0';

    (untested code, but should work).
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. porting application from 32 bit to 64 bit error
    By gandalf_bar in forum Linux Programming
    Replies: 1
    Last Post: 09-14-2005, 09:20 AM
  2. Bit processing in C
    By eliomancini in forum C Programming
    Replies: 8
    Last Post: 06-07-2005, 10:54 AM
  3. Porting from 32 bit machine to 64 bit machine!
    By anoopks in forum C Programming
    Replies: 10
    Last Post: 02-25-2005, 08:02 PM
  4. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM
  5. help with fgets
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-17-2001, 08:18 PM