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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:35:38+00:00 2026-05-31T01:35:38+00:00

Okay so I’m having an issue with a current assignment (trust me this is

  • 0

Okay so I’m having an issue with a current assignment (trust me this is a minuscule part of it) as we are required to write in C code and not C++, and we are not allowed to change certain parts of code. So I have a struct defined:

    typedef struct someStruct {
    int what;
    int something[MAX];
    int another[MAX];
} someType;

in main() I initialize all the values in a defined struct:

someType whatever, *whatptr;

EDIT:of course set the pointer to the struct, trying to simplify the code for the example It is present in my code already

whatptr = &whatever;
whatever.what = 0;
// initialize both arrays to hold 0 at all indexes
// Then I must call a function progRun()
progRun();  //I need to pass struct 'whatever' in some way

Now progRun() looks like this:

void progRun(){
printWhat(&whatever);

    if (whatever.what == 0) {
    //do stuff 
    }
}

I can’t change anything inside this code except what parameters to pass inside the progRun() function and I can add stuff before printWhat(). I’ve tried changing progRun to

void progRun(someType *stptr)

then calling it in main as

progRun(whatptr);

but this causes a stack overflow issue for some reason, I’ve tried stepping through with a debugger and it only occurs when the function is called. Is there a better way to pass the ‘whatever’ struct to the function so it can be passed into progRun() and printWhat() and can access ‘whatever.what’?

Any help would be greatly appreciated! in the meantime I’ll try to figure it myself if I can.

EDIT: Something else must be wrong in the code even though everything else has compiled and ran perfectly fine until this code was added. If I can break down the code and find out what’s wrong I’ll update the question. And no I cannot post the whole code as it is an assignment (this isn’t the goal of the assignment trust me it focuses on data forwarding and more, just need to get this basic thing working) Thank you for help everyone.

EDIT: the MAX number used in the struct for something[MAX] and another[MAX] was extremely large ( I left my desktop that I started this project with back home, I’m currently using an old laptop that can’t handle large arrays). All the answers below, and some of the stuff I used before now works fine.

  • 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-31T01:35:39+00:00Added an answer on May 31, 2026 at 1:35 am
    void progRun(someStruct *ptr) {
        someStruct whatever2 = *ptr;
        printWhat(whatever2);
        if (whatever2.what == 0) { ...
    }
    
    whatptr = &whatever;
    progRun(whatptr);
    

    Your problem was that:

    • you need to pass a pointer to whatever, yet you were passing a variable (whatptr) that had absolutely nothing to do with whatever.

      You need to first assign the pointer to whatever into your pointer variable.

    • You are not dereferencing the pointer in the function

    Alternately, get rid of pointer variables:

    void progRun(someType *stptr) {
        printWhat(*stptr);
        if (stptr->what == 0) { ...
    }
    
    progRun(&whatever);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so my question is this. Say I have a simple C++ code: #include
Okay, I am having trouble with the following piece of code (in a header
Okay I got some good advice for Mobile Detection but still having an issue
Okay i have this problem with every page i make. im not sure what
Okay, so I'm not even sure how to ask this question (much less search
Okay, I'm pretty sure that this is not possible but a client had asked
Okay, not sure if this is even possible to do locally. I'm using Mac
Okay so im working on this php image upload system but for some reason
Okay, so this probably sounds terribly nefarious, but I need such capabilities for my
Okay. I know this looks like the typical Why didn't he just Google it

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.