how to read line by line in c?












-4














I would like to read text files line by line in c.
I saw some examples using fgets. But I don't know if the fgets reads the caracteres until the end of the line, or it will read the amunt of chactrers specified (without stoping at the end of the line).



Best regards.










share|improve this question






















  • man fgets ....
    – William Pursell
    Nov 13 at 17:03










  • Is there anything unclear in the documentation of fgets?
    – Jabberwocky
    Nov 13 at 17:06










  • Go through stackoverflow.com/a/3501681/7622687 instead of using fgets
    – NiksVij
    Nov 13 at 17:07






  • 1




    "I don't know if the fgets reads the caracteres until the end of the line" - You could try it and find out.
    – Broman
    Nov 13 at 17:28






  • 3




    Possible duplicate of C read file line by line
    – Broman
    Nov 13 at 17:29
















-4














I would like to read text files line by line in c.
I saw some examples using fgets. But I don't know if the fgets reads the caracteres until the end of the line, or it will read the amunt of chactrers specified (without stoping at the end of the line).



Best regards.










share|improve this question






















  • man fgets ....
    – William Pursell
    Nov 13 at 17:03










  • Is there anything unclear in the documentation of fgets?
    – Jabberwocky
    Nov 13 at 17:06










  • Go through stackoverflow.com/a/3501681/7622687 instead of using fgets
    – NiksVij
    Nov 13 at 17:07






  • 1




    "I don't know if the fgets reads the caracteres until the end of the line" - You could try it and find out.
    – Broman
    Nov 13 at 17:28






  • 3




    Possible duplicate of C read file line by line
    – Broman
    Nov 13 at 17:29














-4












-4








-4







I would like to read text files line by line in c.
I saw some examples using fgets. But I don't know if the fgets reads the caracteres until the end of the line, or it will read the amunt of chactrers specified (without stoping at the end of the line).



Best regards.










share|improve this question













I would like to read text files line by line in c.
I saw some examples using fgets. But I don't know if the fgets reads the caracteres until the end of the line, or it will read the amunt of chactrers specified (without stoping at the end of the line).



Best regards.







c file io






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 at 17:00









Zaratruta

323316




323316












  • man fgets ....
    – William Pursell
    Nov 13 at 17:03










  • Is there anything unclear in the documentation of fgets?
    – Jabberwocky
    Nov 13 at 17:06










  • Go through stackoverflow.com/a/3501681/7622687 instead of using fgets
    – NiksVij
    Nov 13 at 17:07






  • 1




    "I don't know if the fgets reads the caracteres until the end of the line" - You could try it and find out.
    – Broman
    Nov 13 at 17:28






  • 3




    Possible duplicate of C read file line by line
    – Broman
    Nov 13 at 17:29


















  • man fgets ....
    – William Pursell
    Nov 13 at 17:03










  • Is there anything unclear in the documentation of fgets?
    – Jabberwocky
    Nov 13 at 17:06










  • Go through stackoverflow.com/a/3501681/7622687 instead of using fgets
    – NiksVij
    Nov 13 at 17:07






  • 1




    "I don't know if the fgets reads the caracteres until the end of the line" - You could try it and find out.
    – Broman
    Nov 13 at 17:28






  • 3




    Possible duplicate of C read file line by line
    – Broman
    Nov 13 at 17:29
















man fgets ....
– William Pursell
Nov 13 at 17:03




man fgets ....
– William Pursell
Nov 13 at 17:03












Is there anything unclear in the documentation of fgets?
– Jabberwocky
Nov 13 at 17:06




Is there anything unclear in the documentation of fgets?
– Jabberwocky
Nov 13 at 17:06












Go through stackoverflow.com/a/3501681/7622687 instead of using fgets
– NiksVij
Nov 13 at 17:07




Go through stackoverflow.com/a/3501681/7622687 instead of using fgets
– NiksVij
Nov 13 at 17:07




1




1




"I don't know if the fgets reads the caracteres until the end of the line" - You could try it and find out.
– Broman
Nov 13 at 17:28




"I don't know if the fgets reads the caracteres until the end of the line" - You could try it and find out.
– Broman
Nov 13 at 17:28




3




3




Possible duplicate of C read file line by line
– Broman
Nov 13 at 17:29




Possible duplicate of C read file line by line
– Broman
Nov 13 at 17:29












2 Answers
2






active

oldest

votes


















0














One of many references located here.



fgets - char * fgets ( char * str, int num, FILE * stream );




Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the end-of-file is reached, whichever happens first.



A newline character makes fgets stop reading, but it is considered a
valid character by the function and included in the string copied to
str.




Many code examples out there or check out one of the stackoverflow references listed in the comments to your main question by @NiksVij.






share|improve this answer





























    0














    For future, if you're using a vim editor, try using man fgets. It'll give you some basic info on the function and its parameters. You can use this on literally any function that you're unsure about and it may help to clear some things up (although in my experience it confused things a bit more sometimes since I'm also a beginner)



    fgets reads until either a null-byte (basically ''), the new line character or until it reaches the end of the file.






    share|improve this answer























    • Using vim has nothing to do with using manpages. If you work on almost any non-Windows system, you should know how and when to use a manpage.
      – Jules
      Nov 13 at 20:00











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286047%2fhow-to-read-line-by-line-in-c%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    One of many references located here.



    fgets - char * fgets ( char * str, int num, FILE * stream );




    Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the end-of-file is reached, whichever happens first.



    A newline character makes fgets stop reading, but it is considered a
    valid character by the function and included in the string copied to
    str.




    Many code examples out there or check out one of the stackoverflow references listed in the comments to your main question by @NiksVij.






    share|improve this answer


























      0














      One of many references located here.



      fgets - char * fgets ( char * str, int num, FILE * stream );




      Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the end-of-file is reached, whichever happens first.



      A newline character makes fgets stop reading, but it is considered a
      valid character by the function and included in the string copied to
      str.




      Many code examples out there or check out one of the stackoverflow references listed in the comments to your main question by @NiksVij.






      share|improve this answer
























        0












        0








        0






        One of many references located here.



        fgets - char * fgets ( char * str, int num, FILE * stream );




        Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the end-of-file is reached, whichever happens first.



        A newline character makes fgets stop reading, but it is considered a
        valid character by the function and included in the string copied to
        str.




        Many code examples out there or check out one of the stackoverflow references listed in the comments to your main question by @NiksVij.






        share|improve this answer












        One of many references located here.



        fgets - char * fgets ( char * str, int num, FILE * stream );




        Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the end-of-file is reached, whichever happens first.



        A newline character makes fgets stop reading, but it is considered a
        valid character by the function and included in the string copied to
        str.




        Many code examples out there or check out one of the stackoverflow references listed in the comments to your main question by @NiksVij.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 18:28









        static_cast

        5141415




        5141415

























            0














            For future, if you're using a vim editor, try using man fgets. It'll give you some basic info on the function and its parameters. You can use this on literally any function that you're unsure about and it may help to clear some things up (although in my experience it confused things a bit more sometimes since I'm also a beginner)



            fgets reads until either a null-byte (basically ''), the new line character or until it reaches the end of the file.






            share|improve this answer























            • Using vim has nothing to do with using manpages. If you work on almost any non-Windows system, you should know how and when to use a manpage.
              – Jules
              Nov 13 at 20:00
















            0














            For future, if you're using a vim editor, try using man fgets. It'll give you some basic info on the function and its parameters. You can use this on literally any function that you're unsure about and it may help to clear some things up (although in my experience it confused things a bit more sometimes since I'm also a beginner)



            fgets reads until either a null-byte (basically ''), the new line character or until it reaches the end of the file.






            share|improve this answer























            • Using vim has nothing to do with using manpages. If you work on almost any non-Windows system, you should know how and when to use a manpage.
              – Jules
              Nov 13 at 20:00














            0












            0








            0






            For future, if you're using a vim editor, try using man fgets. It'll give you some basic info on the function and its parameters. You can use this on literally any function that you're unsure about and it may help to clear some things up (although in my experience it confused things a bit more sometimes since I'm also a beginner)



            fgets reads until either a null-byte (basically ''), the new line character or until it reaches the end of the file.






            share|improve this answer














            For future, if you're using a vim editor, try using man fgets. It'll give you some basic info on the function and its parameters. You can use this on literally any function that you're unsure about and it may help to clear some things up (although in my experience it confused things a bit more sometimes since I'm also a beginner)



            fgets reads until either a null-byte (basically ''), the new line character or until it reaches the end of the file.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 13 at 19:49









            OznOg

            2,33411525




            2,33411525










            answered Nov 13 at 18:29









            Kerzell Ramos

            11




            11












            • Using vim has nothing to do with using manpages. If you work on almost any non-Windows system, you should know how and when to use a manpage.
              – Jules
              Nov 13 at 20:00


















            • Using vim has nothing to do with using manpages. If you work on almost any non-Windows system, you should know how and when to use a manpage.
              – Jules
              Nov 13 at 20:00
















            Using vim has nothing to do with using manpages. If you work on almost any non-Windows system, you should know how and when to use a manpage.
            – Jules
            Nov 13 at 20:00




            Using vim has nothing to do with using manpages. If you work on almost any non-Windows system, you should know how and when to use a manpage.
            – Jules
            Nov 13 at 20:00


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286047%2fhow-to-read-line-by-line-in-c%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to pass form data using jquery Ajax to insert data in database?

            National Museum of Racing and Hall of Fame

            Guess what letter conforming each word