Page 1 of 1
NXC: fprintf also for arrays of int?
Posted: 14 Feb 2011, 18:46
by HaWe
hi,
is it allowed to use fprintf also for arrays of int?
e.g.
Code: Select all
int values[256];
int fhandle;
fhandle=fopen("myfile.dat", "w"); // file open -write
fprintf(fhandle, "%d", values); // writes complete array of int?
fclose(fhandle); // file close
next question:
where do have I do specify the fsize?
Re: NXC: fprintf also for arrays of int?
Posted: 14 Feb 2011, 20:47
by m-goldberg
In your signature you say: let NXC reach ACDC! -- but here you are trying to push it off the road. In the Standard C library, printf doesn't allow what you are asking for.
Re: NXC: fprintf also for arrays of int?
Posted: 14 Feb 2011, 20:52
by HaWe
I don't understand quite right what you want to say:
fprintf is both ANSI C and NXC - my question now is related to NXC.
So is it possible to write arrays of int to a file? (It's not documented in the NXC help)
Or should I use fprint instead to your opinion?
At least using ANSI C with arrays of char it seems to work:
Code: Select all
#include <stdio.h>
main() {
FILE *Ptr;
char Line[256]; // array of char
Ptr = fopen("/tmp/OutputFile", "w"); // Open a file for output
while(gets(Line)) // Get data from stdin
{
fprintf(Ptr, "%s\n", Line); // Send char array to file
}
fclose(Ptr);
}
Re: NXC: fprintf also for arrays of int?
Posted: 15 Feb 2011, 02:27
by afanofosc
The implementation of printf and fprintf in the NXC API both support only a single scalar value. They both use the fmtnum enhanced NBC/NXC firmware opcode to format the single value into a string. Neither supports multiple scalar values, strings, or arrays of any kind.
John Hansen