C
Chad
Someone had the following
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *fp = NULL;
char buffer[8];
/* insert argc/argv checking code here */
fp = fopen(argv[1], "w");
if(fp != NULL)
{
while(fgets(buffer, sizeof buffer, stdin))
{
printf("%s", buffer);
fprintf(fp, "%s", buffer);
}
fflush(stdout);
fflush(fp);
fclose(fp);
}
else
{
fprintf(stderr, "Broken tee.\n");
}
return 0;
}
Why did they call fllush()? I thought that flush() got called when you
called fclose(). Is this a coding error? If not, why call fflush()
when reading from stdin.
Chad
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *fp = NULL;
char buffer[8];
/* insert argc/argv checking code here */
fp = fopen(argv[1], "w");
if(fp != NULL)
{
while(fgets(buffer, sizeof buffer, stdin))
{
printf("%s", buffer);
fprintf(fp, "%s", buffer);
}
fflush(stdout);
fflush(fp);
fclose(fp);
}
else
{
fprintf(stderr, "Broken tee.\n");
}
return 0;
}
Why did they call fllush()? I thought that flush() got called when you
called fclose(). Is this a coding error? If not, why call fflush()
when reading from stdin.
Chad