Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8423105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:38:20+00:00 2026-06-10T03:38:20+00:00

If I do : int main(){ const int LENGTH_LINE = 100; char line[LENGTH_LINE]; int

  • 0

If I do :

int main(){
    const int LENGTH_LINE = 100;
    char line[LENGTH_LINE];
    int len;
    FILE* fp = fopen(file.txt,"r");

    fgets(line,LENGTH_LINE,fp);
    len = strlen(line);
    if(line[len-1] == '\n')
       printf("I've a line");

    //This work if the line have \n , but if the end line of the text dont have \n how can do it?


}

I need to know if I take a whole line with fgets because I got a delimiter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:38:21+00:00Added an answer on June 10, 2026 at 3:38 am

    According to http://en.cppreference.com/w/c/io/fgets

    Reads at most count - 1 characters from the given file stream and stores them in str. 
    Parsing stops if end-of-file occurs or a newline character is found, in which case str will contain that newline character.
    

    So, once fgets returns, there are 3 possibilities

    1. LENGTH_LINE was reached
    2. We got a newline
    3. EOF was reached.

    I’m assuming you have a line in cases 2 and 3.

    In this case the detection condition is :

    line[len-1] == '\n' || feof(fp)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <iterator> #include <iostream> using namespace std; const int MAX_NAME_LENGTH=100; int main() { char
Say I have something along the lines of: int main() { const char* someString
The following code #include <iostream> using namespace std; int main() { const char* const
I had this code: int foo(void){ return 1; } int main(void){ static const int
#include <iostream> using namespace std; int main (int argc, char* const argv[]) { int
int main() { char *p,c; for(p=Hello World;c=*p;++p) { printf(%c,c); } } In the above
#include <Windows.h> #include <cstdio> const int KEY=111; void encryptStrA(char* sometext) { int length; length=strlen(sometext);
int main() { return 0; } const uint8_t* byteHunter(const uint8_t *Search, uint16_t sLength, const
int main(void) { char testStr[50] = Hello, world!; char revS[50] = testStr; } I
I found two ways of passing command-line arguments into a character array: int main

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.