This blog is under construction

Friday, 27 April 2012

fgets example in C

Header file:

    char *fgets(char *str, int n, FILE *stream);

     It reads n-1 character from the input stream or stops reading if a newline character is encountered.  And this newline is included in the input string.  '\0' is included as the last character in our input string.  String "str" is returned as the return value on success.  Otherwise, NULL is returned.

fgets function C example:

  int main() {
        char str[100], *ret;
        printf("Enter your string input:\n");
        ret = fgets(str, 90, stdin);
        str[strlen(str) - 1] = '\0';
        printf("Output:\nret: %s\nstr: %s\n", ret, str);
        return 0;

  jp@jp-VirtualBox:~/cpgms/exp$ ./a.out
  Enter your string input:
  hello world
  ret: hello world
  str : hello world

1 comment:

  1. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.

    Data Science Interview Questions

    Angular JS Interview Questions

    Big Data Training in Velachery

    AWS Certified Developer

    Best Resource of Learning Devops

    Blueprism Interview Questions

    Automation Anywhere Interview Questions