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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:21:43+00:00 2026-06-16T17:21:43+00:00

Possible Duplicate: What is EOF in the C programming language? When I was learning

  • 0

Possible Duplicate:
What is EOF in the C programming language?

When I was learning K&R C programming language, I’m trying to write a program which reads some lines from console then output all of the input. I need to use ctrl-z (EOF) to terminate my input stream. But the problem is when I am tapping ctrl-z, the program stopped, all the inputs can’t be outputed to console (the gdb says “Program received signal SIGTSTP, Stopped(user). 0X00132416 in __kernel_vsyscall()”). I tried to use kill function to handle this terminating signal but failed. What can I do to make the console output all the input lines. part of my codes are as follows:

#include<stdio.h>
#include<string.h>

#define MAXLINES   5000     /* possibly max amount of lines */
char *lineptr[MAXLINES];    /* pointers to lines read */

int readlines(char *lineptr[], int nlines);
void writelines(char *lineptr[], int nlines);

main(int argc, char *argv[])
{
    int nlines;         /* number of lines read */


    **if ((nlines = readlines(lineptr, MAXLINES)) >= 0)** {//program finished when I tap ctrl-z 

    writelines(lineptr, nlines);            // from this line can't be run   
    return 0;
    } else {
    printf("input too big to sort\n");
    return 1;
    }
}

#define MAXLEN 1000
int get_line(char *, int);
char *alloc(int);

/* readlines : read the input */
int readlines(char *lineptr[], int maxlines)
{
    int len, nlines;
    char *p, line[MAXLEN];
    nlines = 0;
    while ((len = get_line(line, MAXLEN)) > 0)
    if (nlines >= maxlines || (p = alloc(len)) == NULL)
        return -1;
    else {
        line[len - 1] = '\0';
        strcpy(p, line);
        lineptr[nlines++] = p;
    }
    return nlines;
}

/* writelines : output the readlines */
void writelines(char *lineptr[], int nlines)
{
    int i;

    for (i = 0; i < nlines; i++)
    printf("%s\n", lineptr[i]);
}
  • 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-16T17:21:45+00:00Added an answer on June 16, 2026 at 5:21 pm

    Ctrl+Z sends the the suspend signal on most Linux terminals. On Linux, EOF is usually Ctrl+D.

    Ctrl+Z is EOF on Windows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: EndOfFile in C - EOF I was trying examples from K&R. I
Possible Duplicate: C : How to simulate an EOF? I am currently trying to
Possible Duplicate: PHP EOF shows only one result from loop Hello Seems like I
Possible Duplicate: Why doesn’t getchar() recognise return as EOF in windows console? I'm trying
Possible Duplicate: .eof() loop not working So I have a fairly simple C++ program
Possible Duplicate: Assignment from incompatible pointer type warning I have two structures, one which
Possible Duplicate: Reading from text file until EOF repeats last line c++ EOF running
Possible Duplicate: Testing stream.good() or !stream.eof() reads last line twice I'm working on an
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: Select columns into local variable from sql script using shell script im

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.