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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:33:58+00:00 2026-05-20T03:33:58+00:00

struct Message { char type; double idNum; char *Time; char *asset; bool BS; float

  • 0
    struct Message
{
    char type;
    double idNum;
    char *Time;
    char *asset;
    bool BS;
    float price1;
    int shares1;
    float price2;
    int shares2;        
};
typedef struct Message Message;
struct Asset
        {
            oBook *OrderBook;
            Trade *TradeBook; //will point to the latest trade
            int QtyTraded;
            float ValueTraded;
            char* Time;
        };
typedef struct Asset Asset;
int main(int argc, char*argv[])
    {
        Message* newMessage;
        Asset* Check;
        //manipulation and initialization of Check, so that it holds proper values.

        newMessage = parser("N,2376,01/02/2011 09:15:01.342,JPASSOCIAT FUTSTK 24FEB2011,B,84.05,2000,0,0",newMessage);
    //  MessageProcess(newMessage,AssetMap);
        printf("LAST TRADE ADDRESS %p LAST TRADE TIME %s\n",Check->TradeBook,Check->Time);
    }
    Message*  parser(char *message,Message* new_Message)
    {
        char a[9][256];
        char* tmp =message;
        bool inQuote=0;
        int counter=0;
        int counter2=0;
        new_Message = (Message*)malloc(sizeof(Message));
        while(*tmp!='\0')
        {
            switch(*tmp)
            {
                case ',': if(!inQuote)
                       {    
                        a[counter][counter2]='\0';
                        counter++;
                        counter2=0;
                        }

                      break;
                case '"':
                    inQuote=!inQuote;
                    break;
                default:
                    a[counter][counter2]=*tmp;
                    counter2++;
                    break;
            }
        tmp++;

        }
            a[counter][counter2]='\0';
            new_Message->type = *a[0];
            new_Message->Time  = &a[2][11];
            new_Message->asset = a[3];
            if(*a[4]=='S')
            new_Message->BS = 0;
            else
            new_Message->BS = 1;
            new_Message->price1=atof(a[5]);
            new_Message->shares1=atol(a[6]);
            new_Message->price2=atof(a[7]);
            new_Message->shares2=atol(a[8]);
            new_Message->idNum = atoi(a[1]);
    return(new_Message);
    }

Here there is a serious memory clash, in two variables of different scope. I have investigated using gdb and it seems the address of new_Message->Time is equalling to the address of Check->Time.

They both are structures of different types I am trying to resolve this issue, because, when parser changes the value of new_Message->Time it manipulates the contents of Check->Time

Please do suggest how to solve this problem. I have lost(spent) around 10 hours and counting to resolve this issue, and tons of hair.

Soham

EDIT STRUCTURE DEF ADDED

  • 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-20T03:33:58+00:00Added an answer on May 20, 2026 at 3:33 am

    You’re using an address of the stack allocated object to initialize new_Message->Time = &a[2][11];

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

Sidebar

Related Questions

No related questions found

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.