Hello to every one ....
I'm a Beginner to programming...
I have a folder that contains two sub folders one is "JAVA FILES" and another one is CLASS FILES. I write some java programs and compile it and the output of the compilation it generates the .class file . I want to move the .java file to "JAVA FILES" folder and .class file to the "CLASS FILES" folder.So i write a c program to perform this task My c program code isI would move the file to the subfolder by parsing file name to this program via command line argument.please help me to change my simple program to efficient one[that is code written by c professionals]...... [Sorry for my english] Thank you .....Code:#include <stdio.h> #include <string.h> //check the file extension is related to class or java files int validfile(char * str) { if(strstr(str,".class") || strstr(str,".java")) { // printf("Valid extension"); return 1; } else { // printf("Invalid extension"); return 0; } } int main(int argc,char *argv[]) { FILE *Sourcefile,*Destinationfile; char filename[50]; if(validfile(argv[1]) == 1) { // Open the source file for reading task Sourcefile = fopen(argv[1],"r"); // Check the file is opened without error if(Sourcefile == NULL) { printf("file is not opened something problem in opening file"); return -1; } if(strstr(argv[1],".class")) { //char filename[20]; strcpy(filename,".//CLASS FILES//"); strcat(filename,argv[1]); // printf("%s",filename); } else { //char filename[20]; strcpy(filename,".//JAVA FILES//"); strcat(filename,argv[1]); // printf("%s",filename); } // create the destination file Destinationfile = fopen(filename,"w"); // Check the file is opened without error if(Destinationfile == NULL) { printf("file is not opened something problem in opening file"); return -1; } // copy data from source file to destination file do { int ch = fgetc(Sourcefile); if(!feof(Sourcefile)) fputc(ch,Destinationfile); } while(!feof(Sourcefile)); fclose(Sourcefile); fclose(Destinationfile); remove(argv[1]); } else { printf("File has invalid extensions"); } return 0; }