mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-10-01 15:55:15 +00:00
1 line
7.1 KiB
Plaintext
1 line
7.1 KiB
Plaintext
|
/* */
/* Special Conformance Test 17.2.0.3: Verification of freopen */
/* */
/* Other files needed: spc17.2.0.a - spc17.2.0.d - data files for the test */
/* */
/* Tester needs to verify that the files named spc17.2.0.a - spc17.2.0.d, */
/* and located on the work prefix, have previously been created with the */
/* test Special Conformance 17.2.0.2. */
/* */
/* The first action of the test will be to open spc17.2.0.a, and print its */
/* contents on the screen. The tester needs to verify that the contents are */
/* correct. */
/* */
/* The next action is to verify that standard input is working. The tester */
/* will be prompted for a string; this string will then be written to both */
/* standard out and standard error out. The tester needs to verify that the */
/* output strings are correct. */
/* */
/* The test will then redirect standard in, standard out, and standard error */
/* out. The contents of spc17.2.0.b will be sent to the files spc17.0.c, */
/* the new standard out, and spc17.2.0.d, the new standard error out. The */
/* tester needs to verify that the three files are identical. */
/* */
/* Finally, standard in, standard out, and standard error out will be reset */
/* to their original values. The tester will be prompted for a new string */
/* to be entered from the keyboard. The tester needs to verify that the */
/* string is correctly echoed to the screen twice (once for standard out and */
/* once for standard error out). */
/* */
#include <stdlib.h>
#include <stdio.h>
main ()
{
int i, j;
char s [255]; /* input buffer */
FILE *f1, *f2, *f3, *f4;
FILE *saveStdin, *saveStdout, *saveStderr;
char fn1 [14] = "3/spc17.2.0.a"; /* define filenames */
char fn2 [14] = "3/spc17.2.0.b";
char fn3 [14] = "3/spc17.2.0.c";
char fn4 [14] = "3/spc17.2.0.d";
f1 = fopen (fn1, "r"); /* open for reading */
if (f1 == NULL)
goto Fail;
i = 0;
while ((j = fgetc (f1)) != EOF) /* read successive */
s [i++] = (char) j; /* chars into string */
s [i] = '\0';
printf ("This is the contents of 3/spc17.2.0.a:\n%s\n", s);
f1 = freopen (fn2, "a+", f1); /* reassign file pointer */
if (f1 == NULL)
goto Fail2;
i = fseek (f1, 0L, SEEK_END); /* move to end of file */
if (i)
goto Fail5;
i = fputs ("This is the second line of file 3/spc17.2.0.b", f1);
if (i == EOF)
goto Fail3;
rewind (f1);
i = 0;
while ((j = fgetc (f1)) != EOF) /* read successive */
s [i++] = (char) j; /* chars into string */
s [i] = '\0';
printf ("\nThese are the updated contents of 3/spc17.2.0.b:\n%s\n", s);
/* This part of the test verifies reopening standard in, standard out, and */
/* standard error out. */
printf ("Please enter a string\n"); /* 1st verify that standard in */
j = 0; /* standard out and standard */
while ((i = fgetc (stdin)) != '\n') /* error out
|