Problems using char strings

Guest #1172558
Hello,

I'm using Eclipse with cygwin.

I have an app with a Timer 0 FIQ and a UART0 IRQ. The timer 0 is used to
simulate a PWM. In the UART ISR I have implemented a echo. I also have a
print(char *str) function. The problem is that the only way which the
program runs is declaring a string like that:

char str[100];

str[0]='q';
str[0]='w';
str[0]='e';
str[0]='r';
...

Print(str);

If I do this, everything works fine. But if I try to initialize the
string like this:
str = "qwert"
all interrups don't work anymore.

I have tried declaring:

const char *str;
const char *str = "qwerty";
Print("qwerty");
const char *str = {'q','w','e','r','t','y'};
...

and the conclusion I have at this moment is that if I use in my code the
character "" to indicate a string, it doesn't work.

Do you have any suggestion?
Thatk you very much.
#1172559
> const char *str;
> const char *str = "qwerty";
> Print("qwerty");
> const char *str = {'q','w','e','r','t','y'};
> ...
>

Hi,

I Ansi 'C' you should do this:

char str[] = "hello world";

you need to reserve the space in memory to store your string.

regards

Jonathan
#1172560
Vicente wrote:
> and the conclusion I have at this moment is that if I use in my code the
> character "" to indicate a string, it doesn't work.

In what way does it not work - fails to compile or runtime failure?
Describe the failure mode. Post the build log if it fails to build; post
complete example code rather than fragments in either case. Make sure
that you build with -Wall -Werror, compiler options, and clear up any
warnings.

Perhaps use of literal string constant where a constant is invalid? Hard
to tell from your post.

Clifford

Reply

A question of your own? This thread is over 19 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.