hey guys, i was wondering if you could help me with my problem!
i made a program that uses 3 arguments as inline commands:
argv[0] is the name of the program)
argv [1] is the name of the first file
argv[2] is the name of the second file
The purpose of the program is to write an inline command with these 3 arguments in the form <program_name.exe file1.txt file2.txt> and the program copies the content of file1.txt in file2.txt and then deletes file1.txt (similar to cut command). The thing is that everytime a different name is used and i cant use remove command that takes the destination of the file as an argument. what do you suggest?thanks for your time!
i hope i was clear.

#include <stdio.h>

int main ( int argc, char *argv[] )

     char c;

    if (argc!=3)
           printf("Wrong number of arguments");     
               FILE *file1;
               FILE *file2;                
               file2 = fopen( argv[2], "w" );

               while ((c=fgetc(file1)) != EOF) 
                        fclose( file1);
                        fclose( file2);


Edited 3 Years Ago by mike_2000_17: Fixed formatting

For Removing a file you can use remove macro defined in stdio.h

int remove (const char *filename);

on success it returns 0, but before removing a file be sure that file is closed.

you want to remove argv[1] after copied to argv[2].

if ( remove(argv[1]) == 0)
   printf("Error Removing File!");

I think it could help you..

Edited 6 Years Ago by vinitmittal2008: n/a

This question has already been answered. Start a new discussion instead.