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.

Let's see what you've done so far

#include <stdio.h>

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

     char c;

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

               while ((c=fgetc(file1)) != EOF) 
                        { 
                         fputc(c,file2);
                        }
                        fclose( file1);
                        fclose( file2);

            }
     }

hey... please embed your program code between code tags..

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("Removed!");
else
   printf("Error Removing File!");

I think it could help you..

thank you so much,it worked!sorry about the code, first time here :)

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.