unsigned char buffer[1000]

while(buffer < 0)

num = fread(buffer,1, 1000, original_pointer);
fwrite(buffer,1,num,copy_pointer);

if(buffer > 1000)
{
//this is the place where i am stuck if the buffer exceeds how do i clear it then carry on reading and writing to a file ?

Recommended Answers

All 4 Replies

Just fill the buffer back up and use the resulting count. The previous contents will be overwritten:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    FILE *in = fopen("test.txt", "r");
    char buffer[10];
    size_t n;

    if (in == NULL) {
        perror(NULL);
        return EXIT_FAILURE;
    }

    while ((n = fread(buffer, 1, sizeof buffer, in)) > 0)
        fwrite(buffer, 1, n, stdout);

    fclose(in);

    return 0;
}
commented: genius thats what all im going to say, shes my life saver +1

thanks for your help naure i have tried it but it seems not to copy nothing this is what i have done

while ((n = fread(buffer,1,sizeof buffer, original_pointer)) < 0)
	{
	
	    n = fread(buffer,1, sizeof buffer, original_pointer);
		fwrite(buffer,1, n , copy_pointer);
		
		}

		if((original_pointer !=NULL) && (copy_pointer != NULL))
		{
		fclose(original_pointer);
		fclose(copy_pointer);
		fclose(create_pointer);
		fclose(open_pointer);
		printf("done..... %s  copied to  %s.\n",original_file,archive_name);
		}
{
		if (original_pointer == NULL)
		printf("unable to open original file\n");
		if (copy_pointer == NULL)
		printf("unabe to open copiedied file");
		return 1; 
}
	
	if( create_pointer != NULL)
{
		printf("file created\n");
		fclose(create_pointer);
		return 0;
}
	else
{
		printf("could not create file\n");
		return 1;
}}

Greater than 0, not less than:

while ((n = fread(buffer,1,sizeof buffer, original_pointer)) < 0)
commented: explains stuff verywell, and he is one clever guy +1

thanks adak your a genuis and thanks you too narue your both life savers much appreciated

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.