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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:19:24+00:00 2026-05-29T09:19:24+00:00

I am new to file handling, when I tried to read data from keypad

  • 0

I am new to file handling, when I tried to read data from keypad to file and output the contents of that file on the screen I am not getting the desired result with the code below

/* get data from the keyboared till the end of file and write it to the 
file named "input" agian read the data from this file on to the screen*/

#include <stdio.h>

   int main()
   { 
     FILE *fp;
     char c;
     printf("enter the data from the keyboared\n");

     fp=fopen("input.txt","w");

     while((c=getchar()!=EOF))
     {
       putc(c,fp);
     }

     fclose(fp);

     printf("reading the data from the file named input\n");

     fopen("input.txt","r");

     while((c=getc(fp))!=EOF)
     {
       printf("%c",c);
     }

     fclose(fp);

     return 0;

  }

I am getting output something like this h ?

Also is there a way so that i can find out where on the harddisk this file is created?

  • 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-05-29T09:19:25+00:00Added an answer on May 29, 2026 at 9:19 am

    First up, this is wrong because of precedence.

    while((c=getchar()!=EOF))
                           ^
    

    Instead of storing the character, you will continuously store the comparison between the character and EOF. So you will continuously store a long line of 1.

    Try this:

    while((c=getchar())!=EOF)
                      ^
    

    Second getc and getchar return int. So ch should be int, not char. Using a char could mean the loop will never terminate on some systems.

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

Sidebar

Related Questions

Quite simply: File account = new File(./data/account); account.createNewFile(); Gives me: java.io.IOException: No such file
I'm not very familiar with file handling in ruby. A problem I've come accross
File file = new File(file-type-string-i-want-2000-01-01-01-01-01.conf.gz); Matcher matcher = pattern.compile(\\-(.*)\\-\\d{4})).matcher(fileName); StringBuilder sb = new StringBuilder();
There is a new file [project-name].otares created in Delphi XE2. The wiki says: File
When Eclipse creates a new file ( .c or .h file) in a C
When creating a new file with vim, I would like to automatically add some
Whenever I make a new file in xcode, it puts something like this at
I added a new file F1 and made changes to another file F2 but
This is my code: File TempFiles = new File(Tempfilepath); if (TempFiles.exists()) { String[] child
I try to create a new file inside a JSP and try to save

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.