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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:40:07+00:00 2026-05-27T20:40:07+00:00

I have following Structure in my Program. #define WIFI_DEVICE_NAME 100 #define WIFI_SERIAL_NO 13 #define

  • 0

I have following Structure in my Program.

#define WIFI_DEVICE_NAME 100
#define WIFI_SERIAL_NO 13       
#define WIFI_PROD_NAME 7


typedef struct WiFiDeviceInfo
{
    char name[WIFI_DEVICE_NAME];                
    char fullname [WIFI_DEVICE_NAME];               
    char productname[WIFI_PROD_NAME];               
    char serialnumber[WIFI_SERIAL_NO];              
};

This Struct is used in the various places. Some time some of the fields may remain empty. So while copying using strcpy_s(), it fails. So I tried with strlen() before doing any copy operation.

I modified the struct and came up with the following design.

typedef struct WiFiDeviceInfo
{
    char name[WIFI_DEVICE_NAME];    
    unsigned short nLenName;            
    char fullname [WIFI_DEVICE_NAME];   
    unsigned short nLenFullName;            
    char productname[WIFI_PROD_NAME];
    unsigned short nproductname;                            
    char serialnumber[WIFI_SERIAL_NO];              
};

I can’t use STL here since its legacy code, which doesn’t use STL.
Is there any better way to design the structure.

  • 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-27T20:40:08+00:00Added an answer on May 27, 2026 at 8:40 pm

    This modification is good. Since you are now storing the actual length of string using the member variables, I would suggest that you use pointers to char and allocate required memory at runtime.
    This would be useful from memory perspective. I mean you should do this…

        typedef struct WiFiDeviceInfo
        {
              char* name;    
              unsigned short nLenName;            
              char* fullname;   
              unsigned short nLenFullName;            
              char* productname;
              unsigned short nproductname;                            
              char* serialnumber;    // Convert the serialnumber to a pointer as well
              unsigned short nserialnumber;
        };
    

    Add constructor and destructor to the struct to handle memory, like setting to NULL, delete pointers etc.

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

Sidebar

Related Questions

I have the following structure in the program: Using transaction As New TransactionScope() 'Make
I have the following XML structure: <?xml version=1.0 encoding=utf-8 standalone=yes?> <Root xmlns:xsi=My Program> <NotRoot
I currently have the following code in my program: struct mystruct { int x;
I have the following structure for my project and developer program: developer table id
I have a simple multi-threaded program, with the following structure. public void someFunction() {
Lets say, I have the following text file: Listing 1: Endianess=little AddressModel=32 typedef struct{
I have an XML program in the following structure <Part> <ID>1</ID> <Density>3</Density> <Parameter> <Element>Alloy</Element>
I currently have a program which has the following basic structure main function --
I have the following structure: struct CountCarrier { int *CurrCount; }; And this is
I have following structure with example data: id season_id title 1 1 Intro 2

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.