This blog is under construction

Friday 27 April 2012

fgets example in C

Header file:
    stdio.h

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

Description:
     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:


  #include<stdio.h>
  #include<string.h>
  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;
  }



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



2 comments:

  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

    ReplyDelete
  2. Thanks for sharing information to our knowledge, it helps me plenty keep sharing…

    Python Training Institute in Pune
    Best Python Classes in Pune

    ReplyDelete