hi i made a program that lets a user creates a file and then lets the user open a file that he would like to copy into the new file that he created. now the question is how do i extract the copied file or extract multiple coped file from that file ?

You could try these two functions


size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);

size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);

could you please furtheron thease functions as i am learning c i need to fully understand

The specifics depends on how your program is structured, which you haven't posted, or described in the detail that's needed.

Post your program's code, and give us an example of what you want to do:

*input you have
*processing you want
*output you want

Please, not just a description - but an actual example. Normal language is poor at communicating these kinds of details. Any math is fine as well, of course.

i have a file pointer which which uses the fopen fucnction to create a file then i have another file pointer which opens a file that needs to be copied to the file that the user creates, this can be more than one file being copied but i need somehow to reverse that process and extract all the files

All of us understands C language more easily .. Post part of code u coded so that everyone can get a clear idea what help you want..

hi i cant really post the code as it has to be unique to other student so here is my code, i want to extract the copoed file so how can i do this ?

[/#include<stdio.h>

int main()
{
FILE *original_pointer;
FILE *copy_pointer;
FILE *create_pointer;
FILE *open_pointer;

char archive_name[256];
char buffer[1000];//char variable where text is stored
int num;
char original_file[256];

printf("please give your archive a name:\n");
scanf("%s", &archive_name);
create_pointer = fopen( archive_name, "w");
printf("please type in the path for the file you want to archive\n");
scanf("%s", &original_file);
open_pointer = fopen( original_file, "r");

original_pointer = fopen(original_file,"r");
copy_pointer = fopen( archive_name,"w");
if((original_pointer !=NULL) && (copy_pointer != NULL))
{
/*fread and write have 4 arguments first is teh char variable where
text can be stored, the second specifies te size of the chunks of
text to read or write at a time, third argument specifies total
numbers of charachters to read or write and 4rth arg is a file
pointer to the file to work with
*/


num = fread(buffer,1, 1000, original_pointer);
fwrite(buffer,1,num,copy_pointer);
fclose(original_pointer);
fclose(copy_pointer);
printf("done original file copied to coppied file.\n");
return 0;
}
else
{
if (original_pointer == NULL)
printf("unable to open the archive\n");
if (copy_pointer == NULL) //<==removed semi-colon
printf("unabe to open file to be archived");
return 1;
}

if( create_pointer != NULL)
{
printf("file created\n");
fclose(create_pointer);
return 0;
}
else
{
printf("could not create file\n");
return 1;
}
}

before getting started on how to extract i would like to know how to copy differnt formats like jpg file etc

There are many ways by which u can copy files ..
copying FILE *fs to *ft ...

while( (ch = getc(fs)) != EOF)  
    {  
        putc(ch,ft);  
    }

i can copy files i just waana know how to copy different formats like jpg

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.