473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Pointer subtraction problem, source boost pic

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;
}
}

Jun 27 '08 #1
2 1709
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
Jun 27 '08 #2
On Fri, 18 Apr 2008 23:44:32 +0100, James Salisbury
<we***********@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.
Do you get the error at run-time or at compile time?
>
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);
Where is rx_array defined?
>pnd_point =strchr (rx_array,'£');
dec_point =strchr (rx_array,0x2E);
Is there a reason you didn't use '.'?
>length =(pnd_point - dec_point); // <-----line 244
My compiler does not generate any diagnostic for this line.
>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;
What kind of objects are these?
>}
else
{
portb.0 = 0;
portb.1 = 1;
}
Where is your return statement.
>}

Remove del for email
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
67
by: Ike Naar | last post by:
Hi, Asking your advice on the following subject: Suppose I want to find out whether a given pointer (say, p) of type *T points to an element of a given array (say, a) of type T. A way to...
69
by: fieldfallow | last post by:
Hello all, Before stating my question, I should mention that I'm fairly new to C. Now, I attempted a small demo that prints out the values of C's numeric types, both uninitialised and after...
17
by: Divick | last post by:
Hi, I am designing an API and the problem that I have is more of a design issue. In my API say I have a class A and B, as shown below class A{ public: void doSomethingWithB( B * b) { //do...
13
by: Protoman | last post by:
Here's a non intrusive reference counting smart pointer class I'm working on; I keep getting a "22 C:\Dev-Cpp\SmrtPtr.hpp ISO C++ forbids declaration of `SmrtPtrDB' with no type" error. Code: ...
33
by: Ney André de Mello Zunino | last post by:
Hello. I have written a simple reference-counting smart pointer class template called RefCountPtr<T>. It works in conjunction with another class, ReferenceCountable, which is responsible for the...
11
by: Nindi73 | last post by:
A few days a ago I posted my code for a deep copy pointer which doesn't require the pointee object to have a virtual copy constructor. I need help with checking that it was exception safe and...
18
by: happyvalley | last post by:
Hi, basically, the test function get a char pointer, and assigned a string to it. then the string is passed back by the call-by-reference mechanism. in test(), I reallocate some memory for the...
20
by: junky_fellow | last post by:
Hi, In my previous post I asked if sizeof may be implemented as a function. Somebody pointed a link that says that sizeof may calculated as follows with a warning that it is not guaranteed to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.