/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program that writes a string into a file. */
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#define BUF_SIZE 40


int main() {
    char buf[BUF_SIZE];
    char *name;
    int fd1;

    name = "temp"; 
    if((name = tmpnam(NULL)) == NULL)
        printf("temp file name could not be made. \n");
    else {
        strcpy(buf,"This is a test.");
        if((fd1=open(name,O_RDWR|O_CREAT ))==-1) {
            perror("Cannot open file.\n");
            exit(1);
        }
        write(fd1,buf,BUF_SIZE);
        printf("'%s' has been written to a temporary file.\n",buf);
        close(fd1);
    }
}


