Searching \ for '[PIC]: Tied up with String: OR the String Cheese I' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Tied up with String: OR the String Cheese I'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Tied up with String: OR the String Cheese I'
2001\07\20@102246 by Lawrence Lile

flavicon
face
I am perpetually confused by pointers in C, thus, I avoid them whenever
possible.  (I have the same method of coping with the city bus system -
don't use it)

CCS has a number of string functions, which "return pointers" whatever that
means.  What I'd like to accomplish is this:

I want to concatenate several items into a string, then pass that string to
PRINTF and squirt it out the RS232 port.

One of the strings might be something like  "10:01 AM System ON" or " 7 28
PM System OFF" (note the blinked colon)

Here's a stab at it, prolly fulla bugs:

Char string1[20];
.
.
.

STRCAT(string1, Hours);  // of course, Hours is an INT, not a string, how to
convert to a string?
STRCAT(string1, ':');         // blinky colon
STRCAT(string1, Minutes); // minutes, also still an INT not a string ???
STRCAT(string1, 'PM');  // does this work with a buncha letters?
etc.
Printf(*string1);  // ??????????

Any suggestions are welcome



-- Lawrence Lile
Sr. Project Engineer
Salton inc. Toastmaster Div.
573-446-5661 Voice
573-446-5676 Fax

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2001\07\20@105910 by John Pfaff

flavicon
face
Why not this:

{
   char ampm[3] = "PM";        // This can be set to "AM" or "PM", depending
on time
   int Hours, Minutes;

   printf( "%d:%02d %s", Hours, Minutes, ampm );
}

or even this if you really want to build a string and perhaps use it
elsewhere as well

{
   char string1[20]
   char ampm[3] = "PM";
   int Hours, Minutes;

   sprintf( string1, "%d:%02d %s", Hours, Minutes, AmPm );
   printf( string1 );
}


Lawrence Lile wrote:
{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2001\07\20@112230 by Lawrence Lile

flavicon
face
Oh, yeah, I forgot to say why just printf'ing won't work.  I've got 40
different messages to print, some have numbers in them, some display the
time, some display temperatures, some don't.  It would be simple if they
were all like:

"10:01 AM System ON"

But some of them are also like:

"Soup Temperature 24510F" or
"Error! You Bozo, shut off the power!"   or
"Call 1-800-IMA-DUMMY for help"         and so on.  *

That's why I am thinking that concatenating a string would be the right
approach.  So far my efforts with STRCAT have produced nil for output.  For
instance the simple code:

DO{
    puts(*string1);

    delay_ms(1000);

    strcpy(string2, "A");
    strcat(*string1, *string2);      // concatenate string1 and 'A'

}WHILE(TRUE);

which I imagined might print "A" then "AA" then "AAA"  then "AAAA" etc just
prints a CR-LF over and over.  Phooey.

--Lawrence

*Humor content of messages has been increased to add interest.  Real
messages are not this funny.



{Original Message removed}

2001\07\20@114207 by Robert E. Griffith

flavicon
face
The previous post is the way to solve your problem, but...

If you are programming a PIC you should not fear pointers.  Just realize
that once you have that 'get it' moment they won't be confusing any more.

One thing to keep in mind is that C has a few notation short cuts that make
things less consistant.

Char buffer[20];

This one statement does several things.

1) it sets aside 20 bytes (each char is 1 byte) of memory.
2) it declares a char* named 'buffer'
3) it sets the value of the char* buffer to the beginning of the memory it
set aside.

Number 2 is the confusing part. It does not look like you are declaring a
pointer, but in most respects buffer behaves as if it was declared "char*
buffer"

The next confusing thing; Variables of type char* are assumed to point to a
memory location that has 0 or more byte values that correspond to ASCII
characters (65 means 'A' and is OK, 200 means nothing in ASCII and is not
OK) and ending in the value 0 (NULL).  The 0 lets functions know how long
the string is.

The C compiler sets aside memory for string literals (like "dog") with one
extra byte that it sets to 0 (NULL).

Now strcat only works with char* (pointers to strings).  There are library
functions to convert standard types to there ASCII string representations.

--BobG

{Original Message removed}

2001\07\20@115216 by John Pfaff

flavicon
face
{Quote hidden}

---
Your strcpy is OK, but the strcat won't work.  strcat takes two pointers, but you have dereferenced them.  It will try to use what's
pointed to as a pointer (i.e. if string1[] contains "123", then strcat will try to use '1', or 0x31, as the pointer, likewise with
string2; you can't be sure what you're writing or to where you are writing it).  Use this and see if it helps:

   strcat( string1, string2 );
---
{Quote hidden}

> {Original Message removed}

2001\07\20@122411 by Spehro Pefhany

picon face
At 10:20 AM 7/20/01 -0500, you wrote:

Hi, Lawrence

(BTW, your toaster oven with LCD display, what temperature sensor does
it use??- email privately if you'd prefer)

The rest is long and probably discouraging, but hang in there..

{Quote hidden}

Why can't you let the output device 'concatenate', and you just worry about
sending them out in the correct sequence?

Don't forget that array names (and that's all that strings are in C, unlike
some more sophisticated languages) are pointers.. so if you write:
char my_string[]="Hello, world\n";
then my_string is already a pointer to char

>That's why I am thinking that concatenating a string would be the right
>approach.  So far my efforts with STRCAT have produced nil for output.  For
>instance the simple code:

/* allocate memory for the strings and initialize them */

#define BUF_SIZE 20
char string1[BUF_SIZE]="";                              /* make them globals */
char string2[2]="";

int main(void)
{
do {
 puts(string1);                                        /* appends a newline */
 delay_ms(1000);
 strcpy(string2,"A");
 strcat(string1,string2);
 } while(strlen(string1) < (BUF_SIZE - 1));    /* let's not crash and burn */
return 0;                                              /* stay with the ANSI program */
}

Note: without the last line's conditional the program will invoke the dreaded
Undefined Behavior very quickly... because string has but 20 bytes allocated.
That means it can hold at most 19 characters plus the terminating null. Since
we concatenate before testing the loop and *then* print, we can print at most
BUF_SIZE - 2 characters.

If you want to write a number into a string, use sprintf, which accepts the
same
formating as printf.

sprintf(string1,"Temperature: %d F");

Note that string1 must be long enough to accept the largest possible number
of
characters or Bad Things will happen, as the memory is not dynamically
allocated.

BTW, usually you don't really want to be doing string manipulation like this
with the small micros if you can avoid it, there is not much RAM.. so it is
better to spit out the pieces in the order you want and let the output
device buffer/concatenate/whatever them. Avoiding printf/sprintf is also
nice,
but with what you are doing, probably not practical.

{Quote hidden}

Use sprintf: sprintf(string1, "%02d", Hours);

>> > STRCAT(string1, ':');         // blinky colon

mm.. ':' is not a string, it is a char! Try ":"
Also STRCAT() is not a C library function (but strcat() is..)

>> > STRCAT(string1, Minutes); // minutes, also still an INT not a string ???

Use sprintf.

>> > STRCAT(string1, 'PM');  // does this work with a buncha letters?

Syntax error.. use "PM", which generates a null terminated string literal. The
'X' construct is limited to characters such as 'A' or '\n'.

>> > Printf(*string1);  // ??????????

Printf() is not a C library function, but printf() is, and this is wrong.
You need
something like this..

printf("%s", string1);

I'd probably do the whole thing in one line like this:
printf("%02d:%02d %s\n", Hours, Minutes, am_pm_flag ? "AM" : "PM");

but that would probably just confuse the hell out of you at this point.

>> > Any suggestions are welcome

I suggest you get a good book on C, and a PC C compiler (an old Borland one
will
do) with good watch windows and so on and play with it. It's too frustrating
trying to learn C with a microcontroller setup. IMHO. Your learning will
increase with every mistake, so you want to make mistakes (and fix them) as
quickly as possible.

Best regards,

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
speffspamKILLspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu


2001\07\20@123442 by Dale Botkin

flavicon
face
On Fri, 20 Jul 2001, Lawrence Lile wrote:

> I am perpetually confused by pointers in C, thus, I avoid them whenever
> possible.  (I have the same method of coping with the city bus system -
> don't use it)

I was the same way until I forced myself to read and re-read the K&R C
book until I understood them.  Now I'm not afraid to use them - as long as
I have the book on hand, since I need to re-read it nearly every time!
8-)

{Quote hidden}

Of course there's an atoi() function (ASCII to int) but no itoa().  That's
what printf is for.  You could write your own itoa(), or figure out how to
use printf() for it.

In any case, strcat() needs two pointers, you can't pass it the actual
value of Hours.  You would have to do strcat(string1,&hours); instead...
BUT since Hours is an int, not a string, so that's not good.

> STRCAT(string1, ':');         // blinky colon
> STRCAT(string1, Minutes); // minutes, also still an INT not a string ???
> STRCAT(string1, 'PM');  // does this work with a buncha letters?

Nope.  I do this:
char buffer[10];
strcpy(buffer, "PM");
strcat(string1, buffer);

Note that I don't use *buffer, buffer is already a pointer to the start of
the array buffer[10].

> etc.
> Printf(*string1);  // ??????????

Nope, printf(string).  String is already a pointer to the char array.

>
> Any suggestions are welcome

I feel your pain.  I'd be very tempted to abandon strcat() and instead
build a better mousetrap.  Use strlen() to find the end of the string,
then append whatever you want to it.  You can then use printf() to send
ASCII-converted numbers to that function.  Hey, that's a neat idea...
I think I'll write it!  I've been needing it for a long time anyway.

Dale
--
A train stops at a train station.  A bus stops at a bus station.
On my desk I have a workstation...

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu


2001\07\20@125751 by Lawrence Lile

flavicon
face
> The rest is long and probably discouraging, but hang in there..
>

True, Spehro, so true...

> Note: without the last line's conditional the program will invoke the
dreaded
> Undefined Behavior very quickly... because string has but 20 bytes
allocated.

Ya, I was just trying to write the simplest thing possible to get off the
ground.  Thanks for the reminder to no overrun buffer allocations..

> sprintf(string1,"Temperature: %d F");

This sprintf() must be a Hitech thing - CCS doesn't like it.


> Also STRCAT() is not a C library function (but strcat() is..)

Yeah, I always turn off caps sensitivity, it seems silly to bother with it.
sTrCAt = STRcat = strcaT

> I suggest you get a good book on C, and a PC C compiler (an old Borland
one
> will
> do) with good watch windows and so on and play with it. It's too
frustrating
> trying to learn C with a microcontroller setup. IMHO. Your learning will
> increase with every mistake, so you want to make mistakes (and fix them)
as
> quickly as possible.

With a 16F873 and an In-Circuit Programming port, I can squirt bug-riddled
code into the micro just about as fast as I can write it!  I've got some
books on C, read them, and never did understand pointers yet.

I learned C with a PC compiler, but I'm trying to get this all to work in
the memory-starved PIC and the subset of C called CCS which apparently
leaves out all the useful functions.

This is all helping  - thanks a lot!



-- Lawrence

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu


2001\07\20@125801 by Bob Barr

picon face
Lawrence Lile wrote:
>
>+AD4- The function you're looking for here is 'sprintf'. It takes the
>general
>+AD4- form:
>+AD4-
>+AD4- sprintf(string1, +ACIAJQ-d+ACI-, Hours)+ADs-
>+AD4-
>+AD4- See your docs for details on additional formatting options. It
>'prints'
>the
>+AD4- value to the string and has the same options as 'printf'.
>
>
>Hmmm.  CCS doesn't seem to recognize sprintf.  Anybody got any code for
>this
>one?
>

AARGH!!!

Sorry about the error on my part. I ASSumed that your compiler supported
sprintf. (I don't think that I've ever seen a compiler with printf support
that didn't include the sprintf variant.)

Now, if you will excuse me, I have some egg that I need to remove from my
face.

Regards, Bob


BTW, is there some setting in your mail program that mangles characters?
Your subjects show up with '+AF' stuff instead of the brackets around the
PIC topic tag.


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

--
http://www.piclist.com hint: To leave the PICList
@spam@piclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2001\07\20@132044 by Hans W

flavicon
face
Bob,
True CCS does not doe sprintf(), however they have a variation of printf()
it's a bit strange to setup it goes like this

char* pS;
char Array[20]; // length your choice

void MakeString(char c) // name this function to anything you like
{
  *pS++ = c;
}

Somewhere where you need it, make a call to printf like this

printf( MakeString,"This is the string");

The Array now contains the string "This is the string"

It's handy for converting floats

float fVar ;
fVar = 123.456;
printf( MakeString,"%f", fVar);

Array now contains the ascii of float value 123.456;

May be this has been covered before, I expect it has, hope it helps;

Hans W



Bob Barr wrote:

{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2001\07\20@134612 by Dipperstein, Michael

face picon face
> From: Lawrence Lile [spamBeGonellilespamBeGonespamtoastmaster.com]

...

> > sprintf(string1,"Temperature: %d F");
>
> This sprintf() must be a Hitech thing - CCS doesn't like it.

sprintf() is an ANSI thing.  I think it's in the original K&R C as well, but my
pre-ANSI K&R book is sitting at home and I'm at work, so I can't verify that.

If CCS support variable argument lists (va_arg, va_start, va_end, ...), then you
can easily build your own sprintf.  Of course if they support variable argument
lists, then they probably support vsprintf() and you can use that.

-Mike

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu


2001\07\20@134622 by Spehro Pefhany

picon face
At 12:21 PM 7/20/01 -0400, you wrote:

>sprintf(string1,"Temperature: %d F");

Oops, this should be:
sprintf(string1,"Temperature: %d F", Temperature);

so if Temperature is 330, it will make string1 = "Temperature: 330 F"

And while I'm at it, I'll expand a bit on the below:-

>I'd probably do the whole thing in one line like this:
>printf("%02d:%02d %s\n", Hours, Minutes, am_pm_flag ? "AM" : "PM");

And this would be more aesthetically pleasing, perhaps, as:

printf("%2d:%02d %s\n", Hours, Minutes, am_pm_flag ? "AM" : "PM");

With Hours == 2, Minutes == 3, am_pm_flag == 0, it will output:

" 2:03 PM"   (without the quotes, of course)

To do a blinky cursor (assuming you are updating whatever it is
often enough)

/* print the time with blinking cursor */
printf("%2d%c%02d %s\n", Hours, cursor_on ? ':' : ' ', Minutes, am_pm_flag
? "AM" : "PM");

Note: printf does NOT automatically append a newline, so you can easily
break this up
into pieces if it makes the program simpler.

Best regards,

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
RemoveMEspeffspamTakeThisOuTinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestEraseMEspam.....mitvma.mit.edu


2001\07\20@142404 by Spehro Pefhany

picon face
At 10:42 AM 7/20/01 -0700, you wrote:
>> From: Lawrence Lile [EraseMEllilespamtoastmaster.com]
>
>...
>
>> > sprintf(string1,"Temperature: %d F");
>>
>> This sprintf() must be a Hitech thing - CCS doesn't like it.
>
>sprintf() is an ANSI thing.  I think it's in the original K&R C as well,
but my
>pre-ANSI K&R book is sitting at home and I'm at work, so I can't verify that.

Here's the relevant passage out of the current ANSI/ISO standard:

7.19.6.6 The sprintf function
Synopsis

1 #include <stdio.h>
int sprintf(char * restrict s,
const char * restrict format, ...);

Description
2 The sprintf function is equivalent to fprintf, except that the output is
written into
an array (specified by the argument s) rather than to a stream. A null
character is written
at the end of the characters written; it is not counted as part of the
returned value. If
copying takes place between objects that overlap, the behavior is undefined.
Returns
3 The sprintf function returns the number of characters written in the
array, not
counting the terminating null character, or a negative value if an encoding
error occurred.

Best regards,
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
RemoveMEspeffEraseMEspamEraseMEinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspam_OUTspamKILLspammitvma.mit.edu


2001\07\20@143436 by Lawrence Lile

flavicon
face
Thanks, Hans.  Strange is the word for it.

So far the statement  char* pS;  gets me an error, "identifier is already
used in this scope" which is bS, because that is the only place in the
program it appears.

Now, char* pS; is declaring a variable which is a pointer???  I'm having
quite a bit of trouble figuring out how   *pS++=C; somemehow assigns
anything to the array Array[20].      Shouldn't there be a #byte statement
in there somewhere ... ?

So far, the best I can tell you about pointers is, randomly put stars in
your code, and eventually you'll find a combination that prints a string.
(ugh).

-- Lawrence

{Original Message removed}

2001\07\20@154721 by Lawrence Lile

flavicon
face

Thanks for the short course in pointers!!!!  why didn't they just come out and say it in plain English like you did???

You're right about the "most important thing"  Tried to code this without  pS = &Array[0];, and it works a time or two, then the PIC reboots or locks up or the LCD displays garbage, due to making a random walk through the PIC's memory.  It almost works as well as an IBM PC running Windows 98!  


Trying this now,  crossing fingers...
--Lawrence



{Original Message removed}

2001\07\20@160604 by Lawrence Lile

flavicon
face

>
> This is nonstandard, nonportable, and suffers from major suckitude, but
> if it works for you..

Well, I'm getting somewhere now, and I've also added a Kewl new term to my vocabulary - "Suckitude", thus my poor understanding of C pointers is acquiring less Suckitude by the minute...

This works:

DO{
  hours++;
pString = &Array[0];
printf( MakeString,"Time is: %2U", hours);
 home_lcd();
puts(array);
 delay_ms(1000);
}WHILE(TRUE);


But this don't

DO{
hours++;
pString = &Array[0];
printf( MakeString,"Time is: %2U", hours);
strcpy(string1, " horay!");                                // trying to use STRCPY.. STRCAT to construct a string
strcat(array, string1);                                       // Causes the Dreaded Memory Problem after a couple rounds
home_lcd();
puts(array);
delay_ms(1000);
}WHILE(TRUE);


 


2001\07\20@164043 by Dipperstein, Michael

face picon face
> From: Lawrence Lile [RemoveMEllileTakeThisOuTspamspamtoastmaster.com]

...

{Quote hidden}

Wow! What is MakeString?  Is it a pointer to character?  Does your printf() work
like sprintf()?  how does array get any values in it?  Does MakeString == array?

{Quote hidden}

The strcat() statement causes the contents of string1 to be appended to the
string which starts at the address pointed to by array.

I would expect examining array after each pass, you would see it pointing to
data that looked like this:
" horay!"
" horay! horay!"
" horay! horay! horay!"
" horay! horay! horay! horay!"
...

At some point it's bound to run over some important piece of data.

Based on my guess at what you're trying to do, I think you would want code that
looks like this:

do {
   hours++;

   /* Note: here array is the same as &array[0] */
   printf(array, "Time is: %2U", (hours % 100));
   strcpy(string1, " horay!");
   // trying to use STRCPY.. STRCAT to construct a string
   strcat(array, string1);
   home_lcd();
   puts(array);
   delay_ms(1000);

   /* if the strange printf concatenates, with array, you need
        to make it a null string again */
   array[0] = '\0';

} while(TRUE);

If you're not trying to get practice with strcat and strcpy, this is a better
solution:

do {
   hours++;

   /* Note: here array is the same as &array[0] */
   printf(array, "Time is: %2U horay!", (hours % 100));
   home_lcd();
   puts(array);
   delay_ms(1000);

   /* if the strange printf concatenates, with array, you need
        to make it a null string again */
   array[0] = '\0';

} while(TRUE);

-Mike

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspamspamspamBeGonemitvma.mit.edu


2001\07\20@165531 by Spehro Pefhany

picon face
At 03:05 PM 7/20/01 -0500, Lawrence Lile wrote:

>This works:
>
> DO{
>   hours++;
> pString = &Array[0];                          // you can write pString = Array;
> printf( MakeString,"Time is: %2U", hours);
>  home_lcd();
> puts(array);
>  delay_ms(1000);
> }WHILE(TRUE);

It works if Array is of static duration (i.e. global or declared as
static). That's because
such variables are initialized to 0 at startup. If Array is an automatic
variable (eg.
declared inside main() without the "static" storage class qualifier) then
it won't
_necessarily_ work (but it might). The problem here is that "MakeString"
doesn't actually
make a string, it leaves out the terminating null. 8-( You should put this
in explicitly
(same as below). In the above case, if you start out with Array all zeros,
it will over-write
the non-zero part over and over, and you'll be left with the original
zero(s) to terminate it.

>But this don't
>
> DO{                                                   // do {
> hours++;
> pString = &Array[0];                          // pString = Array;  is the same thing
> printf( MakeString,"Time is: %2U", hours);

Looks like "MakeString" is not adding the terminating \0 at the end
try:  printf( MakeString,"Time is: %2u\0", hours);              // u not U

> strcpy(string1, " horay!");                    // trying to use STRCPY..
STRCAT to construct a string
> strcat(array, string1);                        // Causes the Dreaded
Memory Problem after a couple rounds
> home_lcd();
> puts(array);
> delay_ms(1000);
> }WHILE(TRUE);                                 // while(1)

A very common way to do the infinite loop is:

for(;;)
{
// my program lives here
}

Note:

ANSI C is case-sensitive, so it should be "while" not "WHILE" etc. It may
see like
I am being picky but it will save you a lot of time if you ever want to
port your code
to another processor. Otherwise none of your key words will be recognized.
You could do
#define WHILE while
#define DO do
etc. but why?

BTW, traditionally, all-upper-case is reserved for preprocessor macros such
as constants that
have been #defined, but there is nothing in the language that enforces this.

Best regards,

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
RemoveMEspeffKILLspamspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestSTOPspamspamspam_OUTmitvma.mit.edu


2001\07\20@165955 by Lawrence Lile

flavicon
face

Michael wrote:

>array[0] = '\0';
Yup, that is definitely required or you take the dreaded walk through the weed patch of memory.  Good point, Michael!  I tried it without it, and there are definitely some problems when strcat gets past the end of the array!

> Wow! What is MakeString?  
As you came in on the middle of the conversation, here's the lowdown:  I've been trying to learn different ways of constructing strings in CCS C, also trying to figger out pointers.  Hans W, among others, "pointed" out [pun intended]



>True CCS does not doe sprintf(), however they have a variation of printf()
it's a bit strange to setup it goes like this

char* pS;
char Array[20]; // length your choice

void MakeString(char c) // name this function to anything you like
{
  *pS++ = c;
}

Somewhere where you need it, make a call to printf like this

pS = &Array[0];   // pS now "points" to the first location in the Array
printf( MakeString,"This is the string");

The Array now contains the string "This is the string"

It's handy for converting floats

float fVar ;
fVar = 123.456;
printf( MakeString,"%f", fVar);

Array now contains the ascii of float value 123.456;

May be this has been covered before, I expect it has, hope it helps;

Hans W


-- Lawrence Lile

2001\07\24@045753 by Sergi Sanchez

flavicon
face
> Any suggestions are welcome
Buy the 'C programming language' and read it.

> Sr. Project Engineer
... Engineer???

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservSTOPspamspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body


2001\07\24@122139 by Dale Botkin

flavicon
face
On Tue, 24 Jul 2001, Sergi Sanchez wrote:

> > Any suggestions are welcome
> Buy the 'C programming language' and read it.

If you followed the thread, he did and has.

> > Sr. Project Engineer
> ... Engineer???

Yeah, he's an engineer...  that does not always indicate a high degree of
C programming skills, it's not a prerequisite.  My father is an engineer,
never programmed a line fo code in his life.  Some of us have been using
microprocessors (and larger systems too) for a long, long time but are
still new to C.

Dale
--
A train stops at a train station.  A bus stops at a bus station.
On my desk I have a workstation...

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body


2001\07\26@114025 by John Hallam

flavicon
picon face
On Fri, 20 Jul 2001, Robert E. Griffith wrote:

> One thing to keep in mind is that C has a few notation short cuts that make
> things less consistant.
>
> Char buffer[20];
>
> This one statement does several things.
>
> 1) it sets aside 20 bytes (each char is 1 byte) of memory.
> 2) it declares a char* named 'buffer'
> 3) it sets the value of the char* buffer to the beginning of the memory it
> set aside.
>
> Number 2 is the confusing part. It does not look like you are declaring a
> pointer, but in most respects buffer behaves as if it was declared "char*
> buffer"

       2 and 3 are false, if you think of `buffer' as a pointer (because
it isn't).

       Actually, `buffer' behaves perfectly consistently if you think of
it as a constant which happens to have type (char *), just as 1 is a
constant that happens to have type (int).  The value of the constant
`buffer' is the address of the start of the array you declared.

> The next confusing thing; Variables of type char* are assumed to point to a
> memory location that has 0 or more byte values that correspond to ASCII
> characters (65 means 'A' and is OK, 200 means nothing in ASCII and is not
> OK) and ending in the value 0 (NULL).  The 0 lets functions know how long
> the string is.

       Actually, this is false, if you mean that the C compiler assumes
this.  It is a convention applied by some library functions.  (I should
say that I'm talking about `real' C compilers;  there are probably some
brain-damaged ones that make this kind of assumption.)

> The C compiler sets aside memory for string literals (like "dog") with one
> extra byte that it sets to 0 (NULL).

       This is true.


       John.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\07\26@191406 by Spehro Pefhany

picon face
At 04:39 PM 7/26/01 +0100, you wrote:

>        Actually, `buffer' behaves perfectly consistently if you think of
>it as a constant which happens to have type (char *), just as 1 is a
>constant that happens to have type (int).  The value of the constant
>`buffer' is the address of the start of the array you declared.

I think somebody (the RAmmerman?) had an example where it did *not* behave
as a constant pointer to char.. using sizeof. sizeof() gives the size of the
entire array for an array name, and the size of the pointer for a pointer.

He spoke of array names "decaying" to pointers to char, an interesting
term that is neither in the standard (ISO/IEC 9899:1999 (E))
nor in K&R II.

Best regards,
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
EraseMEspeffspamEraseMEinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\07\26@232129 by Bob Ammerman

picon face
----- Original Message -----
From: "Spehro Pefhany" <@spam@speff@spam@spamspam_OUTINTERLOG.COM>
To: <spamBeGonePICLISTspamKILLspamMITVMA.MIT.EDU>
Sent: Thursday, July 26, 2001 7:15 PM
Subject: Re: [PIC]: Tied up with String: OR the String Cheese Incident


> At 04:39 PM 7/26/01 +0100, you wrote:
>
> >        Actually, `buffer' behaves perfectly consistently if you think of
> >it as a constant which happens to have type (char *), just as 1 is a
> >constant that happens to have type (int).  The value of the constant
> >`buffer' is the address of the start of the array you declared.
>
> I think somebody (the RAmmerman?) had an example where it did *not* behave
> as a constant pointer to char.. using sizeof. sizeof() gives the size of
the
> entire array for an array name, and the size of the pointer for a pointer.

That is correct.

> He spoke of array names "decaying" to pointers to char, an interesting
> term that is neither in the standard (ISO/IEC 9899:1999 (E))
> nor in K&R II.

Yes, I used that term, in quotation marks, and was aware it was not a
standard term. I have seen it used to describe what happens however.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...