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

The Archive Base Latest Questions

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

I am back to C from Java and C#. I am stuck with the

  • 0

I am back to C from Java and C#. I am stuck with the following simple program attempting to read two arrays from a file with a function. Can anyone point out where am I messing up?

Compiler says:
error: invalid operands to binary * (have ‘int *’ and ‘int *’)

The file format is

    4
    1   2   3   4
    23  23  14  11

My ReadFromFile function needs to fill buffers A and B from the file.

#include<stdio.h>

void ReadFromFile (const char* file_name, int *A, int *B, int *length)
{
    FILE* file = fopen (file_name, "r");
    fscanf (file, "%d", length);            
    int i;
    for(i = 0; i < length; i++)
    {
        fscanf (file, "%d", A+i); 
    }  
    for(i = 0; i < length; i++)
    {
        fscanf (file, "%d", B+i); 
    }   
    fclose (file);        
}

int main()
{
    int *A; int *B; int length;
    ReadFromFile("input.txt", A, B, &length);

    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-01T08:55:55+00:00Added an answer on June 1, 2026 at 8:55 am
    void ReadFromFile (const char* file_name, int *A, int *B, int *length)
    /* ... */
        for(i = 0; i < length; i++)
        {
            fscanf (file, "%d", A+i); 
        }
    

    You have passed in a single integer A from main(), but here you are trying to access completely unrelated memory. Same goes for B. Did you mean to allocate A and B as arrays?

    e.g. change:

    int *A; int *B; int length;
    

    to

    int A[100], B[100], length;
    

    or something similar. (Perhaps dynamically allocate the arrays once you know how many you need — or allocate them with malloc(3) and grow them with realloc(3) if you need to.)

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

Sidebar

Related Questions

How to get back from encoded byte[] to java.security.Key? import java.security.Key; import javax.crypto.SecretKey; import
Is there any way to convert from toString back to the object in Java?
I have a datetime coming back from an XML file in the format: 20080916
I am trying to get data back from a PHP file assigned with GET
I have the following JSON coming back from a web service which I am
I'm back with another similar question. I am currently working on a Java program
Scenerio: I'd like to run commands on remote machines from a Java program over
I need to run Sh file from java class.In that java main class is
I've got XML coming back from an Ajax.Request in Ajax.Response.responseXML . My XML actually
How do I force full post-back from a button within an UpdatePanel?

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.