hi sorry for being a pain but im still really stuck
so far i have
Code:
#include <stdio.h>
FILE * fte; // points to a file called fte (file to edit)
FILE * cfte; // points to a file called ctfe copy file to edit)
char array[100];
char name[50]; // receives the file name to open from the user
char name1[50]; // receives the file name to save as from the user
main(void)
{
printf("Enter the name of file to open "); // issues the command to enter the file name
gets(name); // gets the file name from the user
fte=fopen(name,"r"); // gives the command to open the predefined name
{
if (fte==NULL) // tests the file to see if its open if its not it will advise the following message
printf("ERROR - cannot open file please try again %s"); // gives out an error message else;
}
printf ("Enter the name you wish to call the new file"); // asks for a name to call the new file
gets(name1); // gets the name for the new file
cfte=fopen(name1,"r"); // opens the file name1
cfte=fprintf(name1,"w"); // creates the file from the data with the name specified in name1
{
if (cfte==NULL) //checks the file has written
printf("Error cannot write new file! please try again%s"); // relays a message if the file is not written
}
while(fgets(array, sizeof(array), cfte)) //uses fgets
{
fprintf(fte, "%s", array);
fprintf(cfte, "%s",array);
}
fclose(fte);
return 0;
}
i really cant get it to work, I think i understand what its doing but its not doing it.. I cant get to grips with writing to the file.. its all over the place but i think im getting there with your help please could you point me in the right direction