Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

13
  • fgets look to have 3 parameters, 1. charter pointer. 2. int 3. File * What i should enter in second and third parameter? Commented Oct 12, 2009 at 17:04
  • 1
    +1 but note that the line may be longer than the character limit, so you should always check that the line you read ends in a '\n' character. Commented Oct 12, 2009 at 17:04
  • Thanks but i am in little trouble when i am using it, basically i am taking character input before that, which is scanf("%s", name); and then putting your line fgets(address, 100, stdin); it take the first input, which is name and program ends, so it is not coming to second line. But if i just ask for address, it works. How i can make sure it work for second line which is fgets(address, 100, stdin); Commented Oct 12, 2009 at 17:13
  • I don't think I understand your comment; why is the program ending? Can you show us some more of the code? Commented Oct 12, 2009 at 17:15
  • 2
    While we're on this subject (and this is related), due to the weird way in which scanf() handles whitespace, it is advised not to mix calls to fscanf() and calls to fgets() (or other reading utilities) on the same filehandle. The most commonly recommended pattern is to read the code into a string with fgets() and then use sscanf() on that string. That way, we have the best of both worlds, and we have them safely. Commented Oct 12, 2009 at 17:20