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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:42:51+00:00 2026-06-08T14:42:51+00:00

I have read several posts related to my question on C. This indeed help

  • 0

I have read several posts related to my question on C. This indeed help me cut down on my errors. However, I’m still having problems that other posts couldn’t solve for me. Basically, this is what I am trying to do.

Define an array in main. I pass in a pointer to this array to a function. This function will open up a file, parse that file, and put information from that file into the array whose pointer I passed in. Well, it fails.

The errors I get are:

work.c:12: error: array type has incomplete element type
work.c: In function ‘main’:
work.c:20: error: type of formal parameter 1 is incomplete
work.c: At top level:
work.c:25: error: array type has incomplete element type

The entire code follows below. But I think you only need to focus on how I defined my array, and pointer, and so on.

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

//Defining Preprocessed Functions 
char readFile(char array[][], int, int);
//void displayStudentInfo(int*);

//Implements Step 1 and 2 of Student Instuctions
int main(int argc, char* argv[])
{
    int x = 256;
    int y = 256;
    char arrays[x][y]; 
    readFile(&arrays,x,y);
    //displayStudentInfo(&array);
    return 0;
}

char readFile(char array[][], int x, int y)
{
    char line[256]; //Three columns 0, 1, 2 corresponds to firstname, lastname, score. 
    char* string;
    int columns = 3;

    x = 0;
    //int y; //Defines rows and columns of 2D array to store data
    //char array[x][y]; //Defines the array which stores firstname, lastname, and score



    FILE *file;
    file = fopen("input.txt", "r");

    //Test to make sure file can open 

    if(file  == NULL)
    {
        printf("Error: Cannot open file.\n");
        exit(1);
    }
    else
    {
        while(!feof(file))
        {
          /* 
            if(fgets(line, 256, file))//fgets read up to num-1 characters from stream and stores them in line
            {
                printf("%s", line);
            }
            */
            if(fgets(line,256,file)!=NULL)
            {
                for(y = 0; y < columns; y++)
                {
                    array[x][y]=strtok(fgets(line,256,file), " ");
                }
                x++;
            } 
        }
    }
    fclose(file);
}
  • 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-08T14:42:52+00:00Added an answer on June 8, 2026 at 2:42 pm

    You have a few problems. The first two are similar:

    First, you’re using an unbounded array in your function declaration: the compiler needs to know more about the argument, i.e. the dimensions. In this case it’s sufficient to provide one of the dimensions:

    char readFile(char array[][NUM_Y], int, int);
    

    Now the compiler has enough information to handle the array. You can leave off a dimension like this, but it’s usually better to be explicit, and declare the function as:

    char readFile(char array[NUM_X][NUM_Y], int, int);
    

    Next, when you’re declaring your arrays array in main, you’ll need to be more specific about dimensions – similar to the argument list for the function:

    char arrays[x][NUM_Y];
    

    Choose NUM_Y to be more than large enough fit the amount of data that you’ll expect.

    Next, you’re not initializing x and y in main, then you go on to declare an array using those variables. This is bad because these variables can contain any garbage value, including 0, and so you’ll end up with an array of unexpected dimensions/size.

    Finally, when you pass the array to your function, don’t de-reference it, just pass along the variable:

    readFile(arrays, x, y);
    

    In C, when you pass an array to a function, what is actually passed is a pointer to the first element. This means that the array isn’t copied, and so the function has access to the area of memory that it expects to change. I’ll guess that you’re de-referencing because that’s the way that you’ve learned to pass simpler types that you want to change in the function, like ints or structs, but with arrays you don’t need to do this.

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

Sidebar

Related Questions

I have read several posts where users were having this same issue. When compiled,
I have read several related posts but while some of them are for emulators
All, I have read several other posts before posing my question to you. I
I have read several posts on this topic, but have yet to find a
I have read several posts about WSDL and SOAP but still I'm confusing the
I have a question about the exit button. I have read several posts on
I read several posts regarding this but still don't understand how to solve my
I have read several posts about the configuration manager in VS2010 (or before) but
I have read several forums but can't find the solution to this. int sIndex
I have read several questions regarding this but I fear they may be out

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.