Thread: strcat error
View Single Post
  #2   Spotlight this post!  
Unread 13-03-2009, 15:35
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,077
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: strcat error

I think you think that strcat does something that it doesn't. You can't just cast an int to a char * and expect it to work.

How about:

Code:
 int loop=0;
while (IsAuto())
{
     printf("%d iteration\n", ++loop);
}
That is the most direct way to accomplish what you want. Alternatively, here's how to do it with strcat() properly:

Code:
 int loop=0;
while (IsAuto())
{
     char msg[100]; // We can't just declare this as a "char *" without first allocating memory - 100 characters is more than enough
     strcat( msg, itoa(++loops) );
     strcat( msg, " iteration\n");
     printf("%s", msg);
}
The standard C itoa() function takes an integer and returns a C string of the printable characters.

Last edited by Jared Russell : 13-03-2009 at 15:38.
Reply With Quote