Hi, I'm a newbie to programming in general.
I want create two functions to read and write dat from one file to another file.
Function read will read dat from file to buffer, and funtion write these data from buffer to another file. These functions work parallel, it means: Function read will periodic read dat from file to buffer. Function write will write dat periodic from buffer to another file until there are new dat in buffer.
But I dont know about it. Help me,pls.
Thanks!

Recommended Answers

All 3 Replies

>>Function read will periodic read dat from file to buffer
By periodic, do you mean once an minute, hour, day, week, month, or what?

I think you might want to have your program create two threads -- one thread for reading and the other thread for writing. Then the program will have to synchronize access the the comment buffer you mentioned -- look into semaphores.

Thank you. Periodic it means that will read from start to end and return read from start to end.

#include "stdio.h"
main()
{
        FILE *fsource, *fd;
        char ch;
        fsource = fopen("file_name", "r" ) ;
        if ( fsource == NULL )
        {
               puts( "Cannot open source file" ) ;
               exit(0);
        }

        fd = fopen ( "Destination", "w" ) ;
        if( fd == NULL )
        {
               puts ( "Cannot open target file" ) ;
               fclose ( fsource ) ;
               exit( ) ;
        }

        while( (ch = fgetc(fsource)) != EOF )
        {
                       fputc (ch,fd);
        }
        fclose(fsource) ;
        fclose(fd);
}

It copies char by char from one file to another..
u can use

char *gets(char  *line, int MAX , FILE *file);

      int   puts(char  *line, FILE *file);

for reading array of char from a file n write that to other later..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.