mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Initial revision
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
commit
0098375b73
248 changed files with 40027 additions and 0 deletions
37
Examples/stdio-stream.m
Normal file
37
Examples/stdio-stream.m
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* A simple example of writing and reading to a file using the
|
||||
GNU StdioStream object. */
|
||||
|
||||
#include <objects/StdioStream.h>
|
||||
|
||||
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]
|
||||
initWithFilename:"./stdio-stream.txt"
|
||||
fmode:"w"];
|
||||
[stream writeFormat:"testing %d %u %f %f 0x%x \"cow\"\n",
|
||||
1234, 55, 3.14159, 1.23456789, 0xfeedface];
|
||||
[stream free];
|
||||
|
||||
stream = [[StdioStream alloc]
|
||||
initWithFilename:"./stdio-stream.txt"
|
||||
fmode:"r"];
|
||||
count = [stream readFormat:"testing %d %u %f %lf 0x%x \"%a[^\"]\"\n",
|
||||
&i, &u, &f, &d, &ux, &cp];
|
||||
uc = (unsigned char) ux;
|
||||
[stream free];
|
||||
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue