close

Navigation:  Programming language SQC > Built-in functions > Filesystem >

close

Previous pageReturn to chapter overviewNext page

The close() function closes the file associated with the handle. The function returns 0 if successful, -1 to indicate an error.

 

int close (int fd);

 

Example :

 

#define EMBEDTRON "www.embedtron.com"

#define BUFFER_SIZE 20

 

int main() 

{

    char buffer[BUFFER_SIZE];

    

    int len = 0;

    int fh  = 1;

 

    if((fh=open("file.txt","w" )) == -1) 

    {

        printf("Create file failed");

        return -1;

    }

 

    if((len = write(fh,EMBEDTRON,strlen(EMBEDTRON))) != strlen(EMBEDTRON))

    {

        printf("Write data failed");

        return -2;

    }

 

    close(fh);

      

    return 0;

 }