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 8431513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:52:31+00:00 2026-06-10T05:52:31+00:00

I am working through K&R and I’ve attempted to write a program that prints

  • 0

I am working through K&R and I’ve attempted to write a program that prints out all input lines greater than 80 characters. Once I run the program on itself from the terminal I get nothing back. Can anyone tell me where I have gone wrong? Also one part which I am unsure of is the line s[i] = '\0'; – can someone please explain to me what this does?

#include <stdio.h>
#define MAXLINE 1000
#define LENGTH 80

int get_line(char line[], int maxline);

/* program to print all lines longer than 80 characters */
main()
{
    int len;    /*current line length*/
    char line[MAXLINE]; /*current input line*/

    while((len = get_line(line, MAXLINE)) > 0)  /*while length of the line is greater than zero*/
            if (len > LENGTH) { /*if the length is greater than 80*/
                    printf("%s", line); /*print that line*/
                    return 0;               
            }
}

/* getline: read a line into s, return length */
int get_line(char s[], int lim)
{
    int c, i;

        for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i) /*if i is < 1000 & input is = EOF & input is != newline add one*/
            s[i] = c;   /*assign a value to each character*/
    if (c == '\n') {                            
            s[i] = c;
            ++i;
    }
    s[i] = '\0';    /*unsure what '\0' does*/               
    return i;   /*return the length*/
}
  • 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-10T05:52:32+00:00Added an answer on June 10, 2026 at 5:52 am

    The line

    s[i] = '\0';
    

    appends a nul terminator to the string. That’s C-ism that indicates the end of the string.

    As for your issue, this program works just fine for me.

    $ cat line80.c | ./line80
      while((len = get_line(line, MAXLINE)) > 0)              /*while length of the line is greater than zero*/
    
    $ ./line80 < line80.c
      while((len = get_line(line, MAXLINE)) > 0)              /*while length of the line is greater than zero*/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working my way through displaying various data elements from parent & child data,
I'm working through a small file upload script (learning experience) and I noticed that
Working through a zend tutorial & get this message, & not sure where to
I have been working on a Core Data iOS app that works perfectly through
I'm working my way through K&R's 2nd edition, and I've been stumped with this
I'm working through the exercises in the K&R book. Currently I'm stuck at exercise
Working through more book examples- this one is a partial poker program- This segment
I'm working on an asp.net file browser that recursively goes through folder and lists
I'm working through K & R to learn programming. Going well so far, but
I'm working through C++ Template Metaprogramming by Abrahams & Gurtovoy This isn't actually in

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.