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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:10:07+00:00 2026-06-18T08:10:07+00:00

My instructions: Write a program that repeatedly (until end-of-file) reads in a character from

  • 0

My instructions: Write a program that repeatedly (until end-of-file) reads in a character
from the input stream. If the character is upper case, change it to lower case
and write it to the output stream. For all other characters, write the
character unchanged to the output stream.
Use getchar() for input, Use putchar() for output, and use input redirection
for connecting the input file to the program

My project name is Input and my textfile is input.txt. When I run it I type “Input < input.txt” The program just mimics that on the command window though so how do I get it to read from the text file?

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main()
{
  char c, x;


   c=getchar();

  while (c != EOF)
 {

    c=getchar();
     x = tolower(c);
     if (isupper(c))
    {
        putchar(x);

    }
    else 
    {
        putchar(c);

    }

 }
    system("Pause");
}
  • 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-18T08:10:08+00:00Added an answer on June 18, 2026 at 8:10 am

    I believe the problem is that you do not want to go to the program and type in Input < input.txt. Instead, you want to open a terminal program, change directory into the directory containing the project, and then run the program from the command line by writing Input < input.txt. This starts up the program and uses the contents of input.txt as the standard input stream, rather than reading text from the console.

    That said, there are two bugs in your code. First, note that you have the line

    c = getchar();
    

    outside of your loop that does the input reading. You then immediately call

    c = getchar();
    

    again inside the loop. This means that you are discarding the very first character that you read in.

    Second, your loop runs one more time than it needs to. If the second call to getchar() returns EOF, you do not detect this until after the current loop iteration finishes. This is because your check for EOF is at the top of the loop, which isn’t reached until after you’ve already printed out the EOF character. To fix this, consider using the loop-and-a-half idiom and breaking out of the loop in the middle:

    for (;;) {
        /* Read data. */
        if (/* no data left */) break;
    
        /* Process data. */
    }
    

    Stylistically, are you sure that you need both the if and else branches here? Recall that tolower will not change the values of characters that aren’t upper-case, so having one case for upper-case letters and one for lower-case is redundant. You can just output the character produced by tolower without the special cases.

    Hope this helps!

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

Sidebar

Related Questions

We have an asp.net c# program that reads a sheet from an Excel file
Instructions: Write a program that will read a line of text that ends with
My Instructions: Write a program that starts out asking the user for the mean
I need help with my chiper lab. My instructions are: Write a program that
Current assignment needs me to write a program to read a file with instructions
Trying to write a program that asks the user if they want instructions. If
Everything in my code works, its getting input from file, computing average, and outputting.
I'm pretty new to Java, need to write a program that listen to video
I'd like to write a python program that allows the user to key an
I can understand how one can write a program that uses multiple processes or

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.