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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:31:21+00:00 2026-06-09T21:31:21+00:00

Here is the case. In the file fileA.c I have typedef struct MY_STRUCT {

  • 0

Here is the case. In the file “fileA.c” I have

typedef struct MY_STRUCT
{
  int A;
  int B;
  int C;
}MY_STRUCT;

MY_STRUCT Data;

/* Function */
int function(MY_STRUCT *params)
{
  int varA, varB, varC;

  varA = params->A;
  varB = params->B;
  varC = params->C;
}

And I need to fill the struct elements from other routine, for instance, “fileB.c” which contains the following:

extern MY_STRUCT Data;

int function(MY_STRUCT *params);

/* Function  */
void userMain(void)
{
  Data.A = 1254;
  Data.B = 5426;
  Data.C = 1236;

  function(&Data);
}

But I’m getting the error:

“[Error] fileB.c E208: syntax error – token “;” inserted before “Data”

And whe I cross probe the error the compiler take me to the declaration “extern MY_STRUCT Data;”

So my question is how do I accomplish this functionality? I mean, how do I fill the elements of the structure from another function in another file different from the file where I declared the struct?

  • 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-09T21:31:22+00:00Added an answer on June 9, 2026 at 9:31 pm

    Elaborating a bit on @pb2q answer:

    Create a filea.h file with (omitting the defines and stuff):

    struct MY_STRUCT
    {
    (blah blah blah ...)
    };
    
    extern MY_STRUCT Data;
    

    This will declare the struct and tell whoever wants to know that the variable is declared in another file. Then put in filea.c the following lines

    #include "filea.h"     // near the top
    (...)
    MY_STRUCT Data;    // Somewhere meaningful
    

    This will actually declare the variable Data. Finally, in file “fileb.c” type

    #include "filea.h"
    

    that allows you to use the variable Data.

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

Sidebar

Related Questions

Here's the case: We have a file upload page. We didn't want to reload
Ok here I have a switch case statement which is falling through and trying
In case of csv file we have fgetcsv in php to parse and get
I have this code here: case 'resource_list': if(file_exists('content.php')){ include('../ajax/content.php'); } else { die('does not
Here's what I'm trying to do, and failing... I have a File model which
I have an, at least to me, strange case here: I have a relatively
I have this struct: typedef struct { void (*func)(instruction); union { double db; char
I have a function that reads a formatted file. It looks like this: 1;Name_of_the_author;The
Not sure what I'm doing wrong here. I have a struct that is used
Working on a problem where I have to read data from a file into

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.