On Apr 18, 3:44*pm, James Salisbury
<webmail_th...@whatsthis.salisbury.org.ukwrote:
Hi,
Does anyone have a good page and some exercises on the use of pointers?
The compiler is Source Boost and the target is an 18f picr. I am trying
to find out why the code below won't compile. At line 244 I get invalid
operand and failed to generate expression.
Thanks
char get_credit (void)
{
char test_string[]="Your balance is £4.38.";
//char *CUSD = "AT+CUSD=1,*#10#";
char *pnd_point;
char *dec_point;
int length;
char cb [5];
//char pnd='£';
//char dec='.';
int credit_pnd;
int credit_pence;
//puts ("AT+CUSD=1,*#10#");
//gsm_gets (rx_array);
strcpy (rx_array,test_string);
pnd_point =strchr (rx_array,'£');
dec_point =strchr (rx_array,0x2E);
length =(pnd_point - dec_point); // * <-----line 244
strncpy (cb,(pnd_point+1),(length));
credit_pnd = atoi (cb);
strncpy (cb,(dec_point+1),2);
credit_pence = atoi (cb);
if (credit_pnd >5)
{
portb.0 = 1;
portb.1 = 0;}
else
{
portb.0 = 0;
portb.1 = 1;
}
}- Hide quoted text -
- Show quoted text -
#include <string.h>
#include <stdlib.h>
extern char *rx_array;
void get_credit(void)
{
char test_string[] = "Your balance is £4.38.";
char *pnd_point;
char *dec_point;
int length;
char cb[5];
int credit_pnd;
int credit_pence;
strcpy(rx_array, test_string);
pnd_point = strchr(rx_array, '£');
if (pnd_point) {
dec_point = strchr(rx_array, 0x2E);
if (dec_point) {
length = (pnd_point - dec_point);
strncpy(cb, (pnd_point + 1), (length));
credit_pnd = atoi(cb);
strncpy(cb, (dec_point + 1), 2);
credit_pence = atoi(cb);
if (credit_pnd 5) {
/* These assignments look to be the problem.
* It looks like some kind of extension for
* embedded systems to read and write
* directly from and to port numbers. C has
* no provision for this. I guess you will
* have to look at you embedded compiler
* documentation to find out how to do it.
* Clearly, you will also need to define portb,
* probably via the inclusion of a header file.
*/
portb.0 = 1;
portb.1 = 0;
} else {
portb.0 = 0;
portb.1 = 1;
}
}
}
}
I guess you are better off asking your question in
news:comp.arch.embedded