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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:54:08+00:00 2026-06-07T07:54:08+00:00

When I read in a file and then output to a new file, the

  • 0

When I read in a file and then output to a new file, the output is garbled, and I am trying to figure out why.

I am trying to run the following code

#include<stdio.h>
#include<stdlib.h>
int main(int argc ,char *argv[])
{
    int c;
    FILE *of;
    FILE *f;
    of=fopen(argv[2],"w");
    f=fopen(argv[1],"r");
    while(c=getc(f)!=EOF)
        putc(c,of);
    fclose(of);
    fclose(f);
    return 0;

 }

But when I run it as follows
$./a.out temp new

where temp is an existing file whose contents are:
this is a temp file and new doesn’t exist before running the program

But now when I cat the contents of new it is all messed up why it is so?

  • 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-07T07:54:09+00:00Added an answer on June 7, 2026 at 7:54 am
    while(c=getc(f)!=EOF)
    

    needs parentheses,

    while( (c=getc(f)) != EOF)
    

    the precedence of != is higher than that of the assignment =.

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

Sidebar

Related Questions

I'm trying to figure out how I would read a file, and then count
I am trying to read a file and then display the file in ASCII
I am trying to save a file (and then read it later) in java
I'm trying to read a file then append some text to a certain place
I am trying to have PHP read an XML file and then convert it
I want to read a xls file and then parse it. How can i
Basically I want to read and write to a file then save all the
The string in question (read from a file): if (true) then { _this =
I want to read data about MMORPG characters from a .txt file and then
I have a specific requirement to read a resource from jar file and then

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.