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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:54:18+00:00 2026-06-15T23:54:18+00:00

what happens is it gets all the input from fp1 first and then gets

  • 0

what happens is it gets all the input from fp1 first and then gets input from fp2. Why is it that way? Can’t you get input from 2 different file pointers at the same time inside a while statement?

/*checks if 2 text files are identical */
#include <stdio.h>
int main(void)
{
    FILE *fp1,*fp2;
    char buf1,buf2;
    int flag = 1;
    fp1 = fopen("textfile1.txt","r");
    fp2 = fopen("textfile2.txt","r");
    /* putting them inside a while statement causes a logical error? why */
    while(fscanf(fp1,"%c",&buf1) == 1 ||fscanf(fp2,"%c",&buf2) == 1)
    {
        printf("buf1: %c, buf2: %c\n",buf1,buf2);
        if(buf1 != buf2)
        {
            flag = 0;
            //break;
        }
    }
    if(flag == 1)
        printf("SAME");
    else
        printf("NOT SAME");
    fclose(fp1);
    fclose(fp2);
    return 0;
}
  • 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-15T23:54:19+00:00Added an answer on June 15, 2026 at 11:54 pm

    Your while statement is short circuiting. When using the OR (||) operator, if the first expression is true, the second doesn’t not get executed.

    I’m not entirely sure what you’re trying to achieve with the OR (||) operator, maybe you actually need an AND (&&)?

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

Sidebar

Related Questions

I am using Ext.grid.EditorGridPanel to get some input from user. One of the columns
I can't seem to find an example that is complete in all the components.
I've written OpenGL programs in C++ and Python and all the computer that get
I have a div positioning working which gets fired by the scroll-event. What happens
What is supposed to happen is that a row gets inserted into a table,
What happens to http requests that are being processed when you stop or restart
What happens is, I am fetching the data from web service. Simultaneously 6 async
Have a form here with bunch of input text fields and a file upload
I've got a flash 10.1 app that lets me record microphone input to a
Fragile base class is one of the most common point that gets popped up

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.