Hi,
I'm trying to write a program that will ask the user for a file which the wish to copy the contents of and then copy it to another file whilst stripping out the spaces.
but initially i cant seem to be able to get it to copy at all, my window crashes on entering the output file name. can anyone suggest where im going wrong?
Kind RegardsCode:#include<stdio.h> int main(void) { /* Declare Variables */ char inputFile[20]; char outputFile[20]; char copy[256]; /* Ask user to input file name(including extension)*/ printf("Please enter the file name you want to copy: "); scanf("%s", inputFile); /* Ask user to output file name(including extension)*/ printf("Please enter the file name you want to output: "); scanf("%s", outputFile); /* Opens file on a read txt only basis */ FILE *file_pointer=NULL; file_pointer=fopen(inputFile, "rt"); /* Opens file on a write basis */ FILE *file_pointer2=NULL; file_pointer2=fopen(outputFile, "w"); /* Copies the string into a buffer named 'copy' */ while (fgets(copy,256,file_pointer)); { fputs(copy,file_pointer2); } /* A declaration of success */ printf("File %s has been successfully copied to file %s", inputFile, outputFile); }
Ryan



LinkBack URL
About LinkBacks



i passed, thanks so much again. Hope someday I can help people with their programming.