aboutsummaryrefslogtreecommitdiff
path: root/tests/files.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2011-01-16 15:29:06 -0800
committerAlon Zakai <azakai@mozilla.com>2011-01-16 15:29:06 -0800
commit9eb5dd2a45db42c792bb3948271d42016417404e (patch)
tree20225e99c25124227f4f3b967558aa93199f3d8b /tests/files.cpp
parent6a6e842688afe7e15f6a957d4179da982c0f940b (diff)
support for writing to files in stdio
Diffstat (limited to 'tests/files.cpp')
-rw-r--r--tests/files.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/files.cpp b/tests/files.cpp
index a07ef42b..5d915e01 100644
--- a/tests/files.cpp
+++ b/tests/files.cpp
@@ -2,7 +2,10 @@
#include <stdio.h>
#include <stdlib.h>
-int main() {
+int main()
+{
+ // Reading
+
FILE *file = fopen("somefile.binary", "rb");
assert(file);
@@ -25,9 +28,24 @@ int main() {
fclose (file);
free (buffer);
+ // Standard streams
+
fwrite("texto\n", 1, 6, stdout);
fwrite("texte\n", 1, 6, stderr);
+ // Writing
+
+ char data[5] = { 10, 30, 20, 11, 88 };
+ FILE *outf = fopen("go.out", "wb");
+ fwrite(data, 1, 5, outf);
+ fclose(outf);
+
+ char data2[10];
+ FILE *inf = fopen("go.out", "rb");
+ int num = fread(data2, 1, 10, inf);
+ fclose(inf);
+ printf("%d : %d,%d,%d,%d,%d\n", num, data2[0], data2[1], data2[2], data2[3], data2[4]);
+
return 0;
}