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

  • SEARCH
  • Home
  • 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 7733281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:56:55+00:00 2026-06-01T06:56:55+00:00

Since UNIX has all those wonderful filter-like programs (such as grep , sed ,

  • 0

Since UNIX has all those wonderful filter-like programs (such as grep, sed, tr and so forth), what’s the easiest way to write one of those in standard C?

By filter, I mean a program which reads standard input, performs some manipulation of the data, and then writes it to standard output. This is useful in constructing pipelines of commands, with each performing some additional manipulation of the data, such as:

grep xyzzy input.file | tr '[A-Z]' '[a-z]' | sed 's/plugh/PLUGH/g'

(each of the | pipe symbols connects the standard output of the previous command to the standard input of the next, hence the pipeline metaphor).

Let’s say I needed one that converted all uppercase characters to lowercase. And, yes, I realise this particular problem can be solved with the UNIX:

tr '[A-Z]' '[a-z]'

but that’s just an example.

What I’m actually after is the simplest standard C source code to do such a filter.

  • 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-01T06:56:56+00:00Added an answer on June 1, 2026 at 6:56 am

    You could use getline as described by @hroptatyr, but you can do something a lot simpler:

    #include <stdio.h>
    #include <ctype.h>
    int main(void) {
        int c;
        while ((c = getchar()) != EOF)
            putchar(tolower(c));
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize that since UNIX sockets are platform-specific, there has to be some non-Java
I'd like to store a UNIX timestamp (i.e. seconds since epoch) in an Ant
I like to know how much time in second has elapsed since the user
I want to find out the time in unix time (ie seconds since the
I'd like to a convert unix timestamp I have in a string (ex. 1277722499.82)
I need to delete an application (MyApp.app), which has read only permissions in all
How to convert human-friendly date to milliseconds since the unix epoch?
I do not get why Unix has fork() for creating a new process. In
I'm writing a application that acts like a filter: it reads input from a
Module Unix contains the time function to get the seconds since the Epoch but

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.