|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
strcat error
testing out some code, our auto looked similar to this:
Code:
int loop=0;
while (IsAuto())
{
char * name = strcat((char*)(++loop), " iteration");
printf(name);
}
|
|
#2
|
|||||
|
|||||
|
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);
}
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);
}
Last edited by Jared Russell : 13-03-2009 at 15:38. |
|
#3
|
||||
|
||||
|
Re: strcat error
ok, but why is it crashing the crio?
|
|
#4
|
||||
|
||||
|
Re: strcat error
You're taking the loop number and treating it like a pointer , so the rio is trying to access memory at the address of 'loop', which is probably 0 or very low. Basically you're causing a segmentation fault, which probably causes your task on the rio to exit.
|
|
#5
|
||||
|
||||
|
Re: strcat error
ahhh! that would explain that! doesn't one love the power and the unsafeness of C/C++? (there's an easy virus: ((char*)0) = "CORRUPT THIS DATA!!!!";
) |
|
#6
|
||||
|
||||
|
Re: strcat error
Quote:
Now of course, if you're running in the kernel and make a bad memory access, then the system will generally crash, since theres nothing to protect you there. Incidentally, our programs are running as a kernel module on the cRio... |
|
#7
|
|||||
|
|||||
|
Re: strcat error
Pointers are a great and terrible thing. To the point that I've worked on many projects at work where the use of non-smart pointers is strictly prohibited. Simply put, 90% of us aren't smart enough to use them effectively without shooting ourselves in the foot (and I am definitely a member of that majority!)
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| LebView Error -- Error 1055 occured at Property Node in FRC Create Project.vi->FRC Wi | RMS11 | Programming | 8 | 08-12-2008 18:20 |
| Error in code light on, trouble finding error | Bryan Herbst | Programming | 16 | 12-10-2007 21:59 |
| 180:Error: syntax error help! | seanl | Programming | 8 | 04-02-2007 11:31 |
| stupid Array error: Error [1300] stack frame too l | Validius | Programming | 7 | 27-01-2006 10:53 |