avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Bizarre string problem


From: Ian Caddy
Subject: Re: [avr-gcc-list] Bizarre string problem
Date: Mon, 06 Sep 2004 14:31:37 +0800
User-agent: Mozilla Thunderbird 0.6 (Windows/20040502)

Hi Andre,

In your code snippet, why do you use "T" instead of 'T' for the character array.

The code snippet should look like:

char t[1] = 'T';
UDR = t[0];

If you want to copy a string into a char array, you should use string copy:

strcpy(t, "Test");

assuming your array t was big enough to handle the length of the string "Test" which is 5 chars, 4 and a NULL.

The other option is to use a limited length copy called strncpy:

strncpy(t, "Test", sizeof(t));

In your emample you may have been wanting to use a char pointer instead, such as:

char *t = "T";
UDR = t[0];

This should print out the letter T.

I hope this helps.

regards,

Ian Caddy


André - BOL wrote:

Please, help me... I was trying to use UART (atmega32) when I realized
something very strange.
For example: (I'm ommiting a lot of code, of course)
chat t = 'T';
UDR = t; ==> this correctly prints T in my HyperTerminal char t[1] = "T";
UDR = t[0];
==> this prints nothing (Blank space)
I realized writing t[0] to any PORT lights test leds showing that the
value is always 0xff !!!  This problem is giving me a huge head-ache.
There's nothing wrong with this code (from C's point of view). Is there
anything special I should be doing?
Please help me... I'm about to give up avr-gcc. I am generating hex code
and programming the device using Bascom. I don't think that explains
anything, but if anyone can show me how to use avr-dude I'd be very glad
to. It's a very simple single-file project. Uisp doesn't seem to work
under Windows.
Thanks a lot in advance!
Andre
_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list



reply via email to

[Prev in Thread] Current Thread [Next in Thread]