Advertisement

06.13.2008 at 07:38PM PDT, ID: 23484496
[x]
Attachment Details

Global pointer problems

Asked by software_architect in C Programming Language

Tags: C

Hello List,
When the program reaches line 90, I am not sure why I would get no content in ctxt->sdiUser and the strange "s" in ctxt->sdiRequest, as shown in the snapshot in the png file attached.
Just in case of problems accessing, I have attached the completed code as a txt file as well.
The code compiles with no errors.

ArthurStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define AR_MAX_DEFAULT_SIZE 255
 
typedef struct
{
int iInitRun;
char *sdiRequest;
char *sdiResponse;
char *sdiUser;
char *sdiPwd;
char *sdiQ;
char *sdiBrokerList;
} Context;
 
void CreateInstance(void **);
void GLEWF(void **);
void talker(void **);
void onMessage(void **);
void Init(void **);
void DeleteInstance(void **);
void PrintContext(void **);
 
void PrintContext(void **object)
{
    Context *printCtxt = (Context *)object;
//    if((int *)printCtxt->iInitRun != 0)
//    fprintf(stdout,"InitRun - %d\n",printCtxt->iInitRun);
    if(printCtxt->sdiRequest != NULL)
    fprintf(stdout,"sdiRequest - %s\n",printCtxt->sdiRequest);
    if(printCtxt->sdiResponse != NULL)
    fprintf(stdout,"sdiResponse - %s\n",printCtxt->sdiResponse);
    if(printCtxt->sdiUser != NULL)
    fprintf(stdout,"sdiUser - %s\n",printCtxt->sdiUser);
    if(printCtxt->sdiPwd != NULL)
    fprintf(stdout,"sdiPwd - %s\n",printCtxt->sdiPwd);
    if(printCtxt->sdiQ != NULL)
    fprintf(stdout,"sdiQ - %s\n",printCtxt->sdiQ);
    if(printCtxt->sdiBrokerList != NULL)
    fprintf(stdout,"sdiBrokerList - %s",printCtxt->sdiBrokerList);
}
 
void CreateInstance(void **object)
{
  Context *context;
 
  if (object != NULL)
    *object = NULL;
 
  context = (Context *) malloc(sizeof(Context));
 
  if (context == NULL)
  {
    fprintf(stdout,"CI:Error memory allocation for Context");
    return;
  }
 
 
  *object = (void *) context;
  context->sdiUser = (char *)malloc(AR_MAX_DEFAULT_SIZE);
  context->sdiPwd = (char *)malloc(AR_MAX_DEFAULT_SIZE);
  context->sdiQ = (char *)malloc(AR_MAX_DEFAULT_SIZE);
  context->sdiBrokerList = (char *)malloc(AR_MAX_DEFAULT_SIZE);
 
  strcpy(context->sdiUser,"CI:User");
  context->sdiUser[AR_MAX_DEFAULT_SIZE]='\0';
  strcpy(context->sdiPwd,"CI:Pwd");
  context->sdiPwd[AR_MAX_DEFAULT_SIZE]='\0';
  strcpy(context->sdiQ,"CI:Q");
  context->sdiQ[AR_MAX_DEFAULT_SIZE]='\0';
  strcpy(context->sdiBrokerList,"CI:Broker");
  context->sdiBrokerList[AR_MAX_DEFAULT_SIZE]='\0';
 
  //PrintContext(*object);
 
  Init(*object);
}
 
void DeleteInstance(void **object)
{
    Context       *context = (Context *) object;
    PrintContext(*object);
    free(context);
}
 
void GLEWF(void **object)
{
    Context *ctxt = (Context *)object;
    ctxt->sdiRequest = (char *)malloc(AR_MAX_DEFAULT_SIZE);
    strcpy(ctxt->sdiRequest,"From GLEWF:Hello World");
    ctxt->sdiRequest[AR_MAX_DEFAULT_SIZE]='\0';
    PrintContext(*object);
    talker(*object);
    free(ctxt->sdiRequest);
}
 
void talker(void **object)
{
    Context *talkCtxt = (Context *) object;
    fprintf(stdout,"talker:%s\n",talkCtxt->sdiRequest);
    strcpy(talkCtxt->sdiResponse, "From talker:Response");
}
 
void Init(void **object)
{
    Context *initCtxt = (Context *)object;
    fprintf(stdout,"Init:%s\n",initCtxt->sdiUser);
    strcpy(initCtxt->sdiUser,"From Init:Reuben");
}
 
int main()
{
    void **obj;
    CreateInstance(*obj);
    GLEWF(*obj);
    DeleteInstance(*obj);
    //printf("Hello world!\n");
    return 0;
}
Attachments:
 
error_snap
error_snap
 
 
Code
 
[+][-]06.13.2008 at 08:52PM PDT, ID: 21784004

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.13.2008 at 09:25PM PDT, ID: 21784072

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.13.2008 at 09:33PM PDT, ID: 21784091

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.13.2008 at 09:41PM PDT, ID: 21784110

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.13.2008 at 09:42PM PDT, ID: 21784112

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.13.2008 at 09:44PM PDT, ID: 21784113

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.13.2008 at 09:47PM PDT, ID: 21784118

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.13.2008 at 09:53PM PDT, ID: 21784129

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.13.2008 at 09:54PM PDT, ID: 21784134

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.14.2008 at 12:07AM PDT, ID: 21784387

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.14.2008 at 12:45AM PDT, ID: 21784499

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.14.2008 at 01:06AM PDT, ID: 21784554

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: C
Sign Up Now!
Solution Provided By: rowansmith
Participating Experts: 3
Solution Grade: A
 
 
[+][-]06.16.2008 at 06:04AM PDT, ID: 21793144

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.16.2008 at 06:12AM PDT, ID: 21793211

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628