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,*#1 0#");
//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;
}
} 2 1726
On Apr 18, 3:44*pm, James Salisbury
<webmail_th...@ whatsthis.salis bury.org.ukwrot e:
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,*#1 0#");
//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
On Fri, 18 Apr 2008 23:44:32 +0100, James Salisbury
<we***********@ whatsthis.salis bury.org.ukwrot e:
>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,*#1 0#"); //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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 signature.
When developing this lib, I figured that the
pointer-to-member-function, although seemingly an attractive solution,
does not work well for us.
|
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 achieve this would be a linear search through the array:
int ptrInArrSafe(T *p,T *a,int max)
/* check whether p points to an element of a */
|
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 assigning them their maximum defined
values. However, the output of printf() for the long double 'ld' and the
pointer of type void 'v_p', after initialisation don't seem to be right.
The compiler used was gcc (mingw) with '-Wall', '-std=c99' and
|
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 something with b
//possibly store in a list
|
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:
SmrtPtr.hpp
#pragma once
| |
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 actual counting. Here
is the latter's definition:
// --- Begin ReferenceCountable.h ----------
class ReferenceCountable
|
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 exception
neutral/
I got a reply from Bux with his code for a smart pointer with far fewer
lines of code
and more cleaner design, not over engineered like mine.
...
|
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 pointer, the
size is not fixed.
I remember, all new statement should be followed by a delete statement,
is there some memory leak here?
|
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 work on all
implementation.
size_t size_obj = (char*)(&obj + 1) - (char*)(&obj);
I wanted to find out on which implementation this would fail. One of
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |