help please , a fgets question

This is a discussion on help please , a fgets question within the C Programming forums, part of the General Programming Boards category; i have this function that i need to build Code: int isIn(char *name1, char *name2) { char *bufferbig; fgets(bufferbig,256,name1); } ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    8

    help please , a fgets question

    i have this function that i need to build
    Code:
    int isIn(char *name1, char *name2)
    {
    char *bufferbig;
    fgets(bufferbig,256,name1);
    }
    name1 and name2 are file names
    and i'm trying to read the line from there and put it in a string but it won't let me use name1 as the file name
    any leads anyone ?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You need to use fopen on your names to open a file (and to fclose it when done), then you need to allocate space for bufferbig with something like malloc (and of course you will need to free it when you are done).


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You must first open the file with fopen, before you can read from it with fgets.

  4. #4
    Registered User
    Join Date
    May 2011
    Posts
    8
    ohhh ok i get it now
    it was pretty weird there for a second
    thanks a lot helpers !!!

  5. #5
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,657
    Do you need bufferbig outside of the isIn function? If not, allocate it as an array on the stack:

    Code:
    int isIn(const char *name1, char *name2)
    {
        char bufferbig[256];
        fgets(bufferbig,sizeof(bufferbig),name1);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about the fgets()
    By thungmail in forum C Programming
    Replies: 10
    Last Post: 11-05-2009, 03:19 PM
  2. fgets question
    By newbie30 in forum C Programming
    Replies: 5
    Last Post: 08-25-2009, 03:03 AM
  3. fgets question
    By mattyg in forum C Programming
    Replies: 2
    Last Post: 12-01-2008, 04:25 AM
  4. Question on using fgets
    By gp364481 in forum C Programming
    Replies: 6
    Last Post: 10-17-2008, 11:23 AM
  5. fgets question
    By Ash1981 in forum C Programming
    Replies: 12
    Last Post: 01-12-2006, 09:53 AM

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