1994-11-04 16:29:24 +00:00
|
|
|
/* A simple example of writing and reading to a file using the
|
|
|
|
GNU StdioStream object. */
|
|
|
|
|
1998-12-20 21:27:47 +00:00
|
|
|
#include <base/StdioStream.h>
|
1996-04-18 01:53:29 +00:00
|
|
|
#include <Foundation/NSString.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
id stream;
|
|
|
|
int count = 0;
|
|
|
|
int i = 0;
|
|
|
|
float f = 0.0;
|
|
|
|
double d = 0.0;
|
|
|
|
unsigned u = 0;
|
|
|
|
unsigned char uc = 0;
|
|
|
|
unsigned ux = 0;
|
|
|
|
char *cp = NULL;
|
|
|
|
|
|
|
|
stream = [[StdioStream alloc]
|
1996-01-27 00:53:47 +00:00
|
|
|
initWithFilename: @"./stdio-stream.txt"
|
1994-11-04 16:29:24 +00:00
|
|
|
fmode:"w"];
|
1996-01-27 00:53:47 +00:00
|
|
|
[stream writeFormat: @"testing %d %u %f %f 0x%x \"cow\"\n",
|
1994-11-04 16:29:24 +00:00
|
|
|
1234, 55, 3.14159, 1.23456789, 0xfeedface];
|
1995-06-30 20:28:51 +00:00
|
|
|
[stream release];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
stream = [[StdioStream alloc]
|
1996-01-27 00:53:47 +00:00
|
|
|
initWithFilename: @"./stdio-stream.txt"
|
1994-11-04 16:29:24 +00:00
|
|
|
fmode:"r"];
|
1996-01-27 00:53:47 +00:00
|
|
|
count = [stream readFormat: @"testing %d %u %f %lf 0x%x \"%a[^\"]\"\n",
|
1994-11-04 16:29:24 +00:00
|
|
|
&i, &u, &f, &d, &ux, &cp];
|
|
|
|
uc = (unsigned char) ux;
|
1995-06-30 20:28:51 +00:00
|
|
|
[stream release];
|
1994-11-04 16:29:24 +00:00
|
|
|
printf("Read count=%d, int=%d unsigned=%u float=%f double=%f "
|
|
|
|
"uchar=0x%x char*=%s\n",
|
|
|
|
count, i, u, f, d, (unsigned)uc, cp);
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|