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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:52:31+00:00 2026-05-26T19:52:31+00:00

Im still a beginner in C programming and I need a little help writing

  • 0

Im still a beginner in C programming and I need a little help writing a code for my C programming class.

The prompt is: Input for this program is a two-dimensional array of floating point data located in a file named textfile94. The input array will contain 3 rows of data with each row containing 5 columns of data.

  • I want you to use the two-subscript method of dynamic memory
    allocation.
  • Use malloc to create an array that holds pointers.
  • Each element of that array points at another array, which is the row of data.
  • Use malloc in a loop to create your rows.
  • Then you can use two subscript operators [r][c] to get at your data
    to do the summing and averaging that the program calls for.
  • This program calls for hard-coded height and width of the 2D array,
    known ahead of time (3×5, actually).
  • Instead of writing in the literal numbers in your code, I want you to
    create a global constant variable to hold those dimensions, and use
    those in your code.

Here is my code:

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

#define int rows = 3;
#define int columns = 5;

float array[rows][columns];

int main(int argc, char* argv[]){
    FILE* fin;
    float x;
    int i,j;
    int* array;

    fin = fopen("textfile94", "r");
    fscanf(fin,"%f", &x);
    array =(int*) malloc(rows* sizeof(int*));

    for(i=0;i<rows;i++){
            for(j=0;j<columns;j++)
              array[i]=(int*)malloc(columns* sizeof(int));
    }
    printf("The Average values for the three rows are:[%f]",array[i]);
    printf("The Average values for the five columns are:[%f]", array[j]);
    return 0;
}

In text file: 4.33 5.33 1.11 99.00 100.00 1.0 33.3 12.5 1.1 -1000.00 22.1 11.9 2.4 8.3 8.9

The program should output:
The average values for the three rows are: 41.95 -190.42 10.32
The average values for the five columns are: 9.14 16.84 5.33 36.13 -297.7

Having Trouble getting it to do this correctly, any help would be appreciated. I don’t want the answer I want to learn from this but just need some hints. Thank you.

Updated Code:

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

#define ROWS 3
#define COLUMNS 5

float array[ROWS][COLUMNS];

int main(int argc, char* argv[]){

FILE* fin;
int i;
float x;
float** array;

fin = fopen("textfile94", "r");
array=(float**) malloc(ROWS*sizeof(float*));
    for(i=0;i<ROWS;i++)
      array[ROWS]=(float*)malloc(COLUMNS*sizeof(float));
    for(j=0;j<COLUMNS;j++){
      fscanf(fin,"%f",&x);
      x = array[ROWS][COLUMNS];
}
printf("The Average values for the three rows are:%f", array[ROWS]);
printf("The Average values for the five columns are:%f", array[COLUMNS]);
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-05-26T19:52:32+00:00Added an answer on May 26, 2026 at 7:52 pm

    Ok, I’ll see what I can add.

    Defines are not written like that, and by convention should be all upper case

    #define ROWS 3
    #define COLUMNS 5
    

    He wants you to dynamically allocate the array via malloc, you are now statically allocating a 2-dimensional array of floats and then you try to force arrays of ints into it. You should look up how to do multidimensional arrays with malloc.

    Basically what you want is

    float **array;
    

    Now array is a pointer to pointer to float, then assign array rows number of pointers to float.

    ROWS * sizeof(float*)
    

    After that you can for each row assign array[row] with

    COLUMNS * sizeof(float)
    

    Now you have your array[ROWS][COLUMNS] structure

    One approach to reading in the data in pythonesque pseudo code would be

    for(row 1..3)
        array[row] = malloc(...)
        for(col 1..5)
            fscanf(value)
            array[row][col] = value
    

    Tell me if I am being too vague, trying to give hints without giving the code.

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

Sidebar

Related Questions

I'm still a beginner at regex so this is a little above me currently.
I am still a beginner but I want to write a character-recognition-program. This program
still new to the world of linq, and i need some help flatening a
I'm very much still a beginner at programming but I have come across the
learning about loops (still a beginner) in VB.net. I have got the below code
Okay, a little preface: I am still a beginner when it comes to AJAX,
I'm a beginner in programming and I've read several tutorials. I'm still unclear about
I'm still a beginner and I have been trying to solve this problem by
I'm writing a program that calculates input a user gives, simple numbers. 2, 4,
I'm still a beginner in programming GUI using c++ winapi32, and I found something

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.