May 17, 2024, 12:49:27 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Pointer math question

Started by Rock Ridge Farm (Larry), March 17, 2006, 07:26:08 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rock Ridge Farm (Larry)

In C this works:
    char buffer[80],*ptr;

    /* buffer contains "abc123" */
    *ptr = &buffer[0];
    *ptr++;

Aurora does not like '*ptr++".
How would I do this?

Ionic Wind Support Team

Well it depends on what your trying to do.  If your reading the buffer and then incrementing the pointer then you need two statements.

chr = *ptr;
ptr++;

Ionic Wind Support Team

Rock Ridge Farm (Larry)

I am trying to move to the next char position in the buffer.
I am doing *ptr++ should it be ptr++ with no *?

Ionic Wind Support Team

Yes.  *ptr dereferences the pointer and returns a character.

ptr++;   increments the pointer
Ionic Wind Support Team

Rock Ridge Farm (Larry)

This is the code I am trying to make work:

InternetReadFile(hhttp,buffer,254,br);
buffer = left$(buffer,br);
IF(br) {
ptr = buffer;
ptr++;
while(*ptr != '"' && *ptr != null)
                ptr++;
if(*ptr == ',')
ptr++;
cst = *ptr;
while(*ptr != ',' && *ptr != null)
ptr++;
ptr = null;
ptr++;
m_lstprc = USING("#######.##&",cst);
hstmt_update = NULL;
hstmt_update = m_db.PrepareSQL("UPDATE stock SET lstprc=? WHERE               id="+NumToStr(m_id));

       m_db.BindParameter(hstmt_update,1,m_lstprc,TYPE_double,8);
       m_db.Execute(hstmt_update);
       m_db.FreeSQL(hstmt_update);

      messagebox(0, buffer,"Quote");
}

I have tried many combinations of * and no * still not working.

Ionic Wind Support Team

You've got a mix of C and Aurora there.

&& in C is AND in Aurora
== in C is = in Aurora

Fix those problems first.

Use a string type and get rid of the pointers if you wish. Remember in Aurora a string can be accessed like an array directly.

dstring buffer[80];
...
int ptr =1;
while((buffer[ptr] != '"') AND (buffer[ptr] != null))
    ptr++;
if(buffer[ptr] = ',')
    ptr++;

Or forge ahead with pointers and see how much you can learn.
Ionic Wind Support Team