a simple question

This is a discussion on a simple question within the C Programming forums, part of the General Programming Boards category; What does it mean? fgets(y, sizeof(y), stdin); thx!...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    101

    a simple question

    What does it mean?
    fgets(y, sizeof(y), stdin);

    thx!

  2. #2
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    #include <stdio.h>
    char *fgets(char *s, int n, FILE *stream);

    Description

    Gets a string from a stream.
    fgets reads characters from stream into the string s. The function stops reading when it reads either n - 1 characters or a newline character whichever comes first. fgets retains the newline character at the end of s. A null byte is appended to s to mark the end of the string.

    Return Value

    On success fgets returns the string pointed to by s; it returns NULL on end-of-file or error.
    please use more descriptive post titles as it will help you get better answers. and try searching on your own first, even if your compiler's editor did not include a help reference for your standard library functions, there are many resources elsewhere.
    hasafraggin shizigishin oppashigger...

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    101
    Originally posted by doubleanti


    please use more descriptive post titles as it will help you get better answers. and try searching on your own first, even if your compiler's editor did not include a help reference for your standard library functions, there are many resources elsewhere.
    I'm sorry.
    I wanna know what does "fgets(y, sizeof(y), stdin);
    " mean in below codes:
    Code:
    #include "stdio.h"
    
    void main()
    {
    char y[30];
    
    printf("Enter a string : ");
    
    fgets(y, sizeof(y), stdin);
    
    printf("The input was : %s \n", y);
    
    return;
    
    }
    thx!!~

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    >char *fgets(char *s, int n, FILE *stream);
    >Description
    >Gets a string from a stream.
    In your code,
    the string is called y
    the stream is called stdin

    Simply put, it reads a string from stdin

    I guess you're really wondering what stdin is, well its normally your keyboard

    Oh, one more thing
    > void main()
    should be int main ()

    And
    > return;
    should be return 0;

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    101
    Originally posted by Salem
    >char *fgets(char *s, int n, FILE *stream);
    >Description
    >Gets a string from a stream.
    In your code,
    the string is called y
    the stream is called stdin

    Simply put, it reads a string from stdin

    I guess you're really wondering what stdin is, well its normally your keyboard

    Oh, one more thing
    > void main()
    should be int main ()

    And
    > return;
    should be return 0;

    I want to know why you think "main() should return an integer value "?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    > I want to know why you think "main() should return an integer value "?
    Try reading the language standard
    http://anubis.dkuug.dk/JTC1/SC22/WG14/www/docs/n869/

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    101
    Originally posted by Salem
    > I want to know why you think "main() should return an integer value "?
    Try reading the language standard
    http://anubis.dkuug.dk/JTC1/SC22/WG14/www/docs/n869/
    oic, thx!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 09:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-21-2005, 12:41 AM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM

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