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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:21:29+00:00 2026-06-03T05:21:29+00:00

Not any homework, but seem to have got lost while doing basics, hence asking.

  • 0

Not any homework, but seem to have got lost while doing basics, hence asking.

Say I have 2 C source files. 1.c & 2.c

2.c is as follows:

typedef struct mystr_
{
    int a;
    float b;
}mystr;

void fun()
{
    mystr q;

    some code....
}

And 1.c is as below:

#include "stdio.h"

void fun();


main()
{
    //How to access / declare a variable of type mystr here.

    mystr *v1;//This obviously gives compiler errors

      some code....    

}

How to access the structure mystr defined in 2.c from file 1.c to have variables of that struct type there?

EDIT:

Sorry forgot to mention in OP. I cannot move the declaration out in a header file for some reason –> It is a quick hack that I am trying to check in a existing code. Then is there any way to access it directly from the other source 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-03T05:21:31+00:00Added an answer on June 3, 2026 at 5:21 am

    Use headers.

    Create a file 2.h

    typedef struct mystr_
    {
        int a;
        float b;
    }mystr;
    

    And include it in 1.c

    #include "2.h"
    #include "stdio.h"
    
    void void fun();
    

    EDIT:
    Because you are not able to extract the declaration into a header file and include it, there is no other way than copying the declaration. This is a highly fragile construct, quick but mainly dirty and not really recommended unless you are out of other options.

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

Sidebar

Related Questions

It might be for pedantic purposes but not homework. I have below question about
So I'll admit that this is a homework assignment, but I'm not asking you
(Before anyone asks, it's not homework.) Say you have 2 Arrays y0 and y1
Saying right now: Yes, this is homework. I'm not asking for an answer, but
I'm not asking for anyone to do this homework for me, but I bring
I have not changed any of the configuration options for sessions in my php.ini.
I have not done any animation stuff with iphone development so far. Can anybody
I'm not doing any fancy route patterns yet, just the basic controller, action, id
I have not done any large game development projects, only messed around with little
I have not found any way to successfully set a screen resolution on my

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.