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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:28:49+00:00 2026-06-05T01:28:49+00:00

Having a problem with print strings from structs in C… typedef struct box{ char

  • 0

Having a problem with print strings from structs in C…

typedef struct box{
    char *REF_OR_SYS; int num, x, y, w, h, o;
}BOX;

sscanf(str, "%s %d %d %d %d %d %d", &label, &refNum, &x, &y, &w, &h, &o);
BOX detect = {label, refNum, x, y, w, h, o};
printf("\nLABEL IS %s\n", detect.REF_OR_SYS); //Prints out the String correctly
                                              //(Either the word REF or SYS)
return detect;

When this is structure is passed to another structure, everything is displayed right EXCEPT for the string..

void printBox(BOX detect){
printf("Type: %s    Ref: %d    X: %d    Y: %d    W: %d    H: %d    O:%d\n", 
 detect.REF_OR_SYS, detect.num, detect.x, 
 detect.y, detect.w, detect.h, detect.o);

}

Am I missing something simple? REF_OR_SYS always prints out as ??_?

  • 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-05T01:28:51+00:00Added an answer on June 5, 2026 at 1:28 am

    Use strdup() (usually available, if not use malloc()) to copy the string read into label by sscanf():

    detect.REF_OR_SYS = strdup(label);
    

    as when that function returns label is out of scope and REF_OR_SYS will be a dangling pointer. Remember to free() it when no longer required.

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

Sidebar

Related Questions

Problem : Trying to sort an array coming from a typedef struct I created
I'm having a problem with getting this code to print out to file due
I'm having a strange problem comparing strings. I send a string to my server
I'm having a problem reading and processing data from my server. I've spent hours
I am currently having a problem selecting a certain item from a mySQL database.
I am currently having a problem accessing Windows print shares ( at work, so
I'm having a JTextField problem. I am needing to get text from a JTextField
I am having some problems when returning with printf of a char array from
I'm having a problem when trying to apply a regular expression to some strings
I know I'm having a problem with a conversion from Unicode but I'm not

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.