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

  • Home
  • SEARCH
  • 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 7188785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:09:36+00:00 2026-05-28T19:09:36+00:00

Hello i am trying to return a struct from a function but i cant

  • 0

Hello i am trying to return a struct from a function but i cant find a way to do so without declaring the struct as global. How can this be done? Here is the code (THIS WORKS AS IT IS)

...
void log_in();
struct node
{
    char name_log[20];
    int passlog;
    int user_point;
}tmp;

int main()
{
  ...
  else if(sel=='2')
  {
     log_in();
     if (tmp.passlog==TRUE)
     logged_in(tmp.name_log,tmp.user_point);  //and here i want to use the retun values
  }

void log_in()
{
   ... //make the changes in the struct
}
...

What i want to achieve is to place the struct node declaration within main but sadly it wont work. So here is what i am trying to do: (THIS DOESN’T WORK)

...
struct node log_in();

int main() {
    ...
    else if(sel=='2') {
        struct node //here is where i want to declare
        {
            char name_log[20];
            int passlog;
            int user_point;
        }tmp;

        log_in();
        if (tmp.passlog==TRUE)
            logged_in(tmp.name_log,tmp.user_point); //and here i want to use the retun values
    }

    struct node log_in()
    {
        ...
        return tmp;
    }
    ...
  • 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-28T19:09:37+00:00Added an answer on May 28, 2026 at 7:09 pm
     else if(sel=='2')            //or within this block but I don't know how.
      {  struct node tmp;
         tmp=log_in();
         if (tmp.passlog==TRUE)
         logged_in(tmp.name_log,tmp.user_point);  //and here I want to use the return values
      }
    

    and inside the function log_in()

    struct node log_in()
    { 
     struct tmp
     ...
     return tmp;
    }
    

    use a local variable inside the function and return this variable. Assign it to another variable inside main().

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

Sidebar

Related Questions

Hello I'm trying something .. I was reading Jquery traversing documentations some forums, this
Hello everyone I am trying to resize an image of 700kb with imagecreatefromjpeg. This
Hello everyone I'm trying to improve my Java skills by solving some problems from
I am trying to pass a variable from a function to a class. Example
I'm trying to implement the times() function in C programming. I'm using the struct
Hello I've been trying to figure out generic way to log http requests in
Hello Functional C# Friends, So this time i am trying to compact my code
Hello can anybody solve this please I'm creating the object in the action class
I'm trying to marshal a struct from a byte[]. Each part works except marshaling
Hello I'm having trouble figuring this out. I have these structs and classes. struct

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.