hi, here something I wrote, I've got a file error when running.
It seems there is a problem accessing the array !
string str[];
int NbStr=0;
void sub();
{
NbStr=0;
if (something)
{
NbStr+=1;
str[NbStr]="Q";
}
if (something)
{
NbStr+=1;
str[NbStr]="R";
}
}
task main()
{
int i;
while (true)
{
sub();
if (NbStr>0)
{
for (i=1;i<=NbStr;i++)
{
TextOut(i*8,LCD_LINE3,str); // here is the line that causes the error !
}
}
}
}
what is wrong there ???
thanks in advance.
Help needed on NXC
Re: Help needed on NXC
I think if you allocate your string array to have more than zero elements then you will not get the File Error message.
But I am not sure what you intend, exactly. Are you trying to grow the string array over time or should it have a fixed size?
John Hansen
Code: Select all
string str[10];
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: Help needed on NXC
thanks ! It works !afanofosc wrote:I think if you allocate your string array to have more than zero elements then you will not get the File Error message.
But I am not sure what you intend, exactly. Are you trying to grow the string array over time or should it have a fixed size?Code: Select all
string str[10];
John Hansen
Fixed size is enough for my use.
Re: Help needed on NXC
Something to keep in mind is that with C and many other programming languages the first element in array has an index of zero rather than one. So if NbStr is == 0 then you would modify the first element in the array but if NbStr is == 1 then you would actually modify the second element in the array so its size would need to be at least 2. You should iterate through an array in C from 0 through N-1 where N is the size of the array.
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Who is online
Users browsing this forum: No registered users and 0 guests