how to read line by line in c?
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
|
show 1 more comment
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
man fgets....
– William Pursell
Nov 13 at 17:03
Is there anything unclear in the documentation offgets?
– 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
|
show 1 more comment
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
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
c file io
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 offgets?
– 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
|
show 1 more comment
man fgets....
– William Pursell
Nov 13 at 17:03
Is there anything unclear in the documentation offgets?
– 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
|
show 1 more comment
2 Answers
2
active
oldest
votes
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.
add a comment |
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.
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 13 at 18:28
static_cast
5141415
5141415
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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