/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program that flushes the buffer
after write operation. */ 
#include <stdio.h>
#include <stdlib.h>
#define SIZE 80

int main() {
    FILE *stream;
    char buf[SIZE]; 
    char *name;
    size_t num;
    
    if((name = tmpnam(NULL)) == NULL)
        printf("Error in creating temp file.\n");
    /* open file for reading and writing */
    if((stream = fopen(name,"w")) == NULL) { 
        printf("cannot open file\n");
        exit(1);
    }
    strcpy(buf,"1111111111111111");
    num = fwrite(buf,sizeof(char),10,stream);
    printf("Number of elements written to temp file: %d\n", num);
    fflush(stream);      // flush the buffer
    fclose(stream);
    remove(name);
}
