Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

file copying program in c using command line interface

Please help me make a program in C for copying one file to another using command line interface.Please do explain the program made in detail

Comments

  • DonotaloDonotalo Member Posts: 715
    : Please help me make a program in C for copying one file to another using command line interface.Please do explain the program made in detail
    :
    programmers' heaven's programmers are not here to do others homeworks. they will help if u show ur effort and ask very specific question. however, here is a guidline:
    [code][red]
    Read the name of the first file (to be copied) from the user...
    Ask the user for the name of the second file...
    Read each character from the first file until u reach at EOF...
    Write that character into the second file...
    [/red][/code]
    that's it!
  • RIGHT_THENRIGHT_THEN Member Posts: 154
    : Please help me make a program in C for copying one file to another using command line interface.Please do explain the program made in detail
    :

    I AM WRITING THIS FOR YOU AS APPRECIATION FOR PROGRAMMERS
    WHO SHARE THERE EXPERIENCES TO MAKE OTHERS UNDERSTAND
    BETTER AND PROGRAMMERS ON THIS FORUM WHO HAVE SCRATCHED
    THEIR HEAD FOR MY SAKE AND I NEED THEM TO SCRATCH IT MORE
    BECAUSE I AM NOT DONE LEARNING YET ;- ;-) HERE WE GO THEN

    CAUTION:- DONOT CHANGE EVEN A BIT IN THIS PROGRAMM NOT EVEN A SPACE
    CUT COPY AND PASTE IT ON YOUR DESKTOP AS .C FILE AND RENAME IT
    WHATEVER YOU WANT TO CALL YOUR COMMAND.THEN ASSCESS IT FROM YOUR
    C DOS MODE IT IS SO.IF IT IS WINDOWS THEN ALLRIGHT .
    BUT DONT CHANGE ANYTHING UNLESS IT IS NOT WORKING.
    DONT TYPE IT CUT AND PASTE IT ONLY.ONCE YOU UNDERSTAND IT THEN
    DO WHATEVER YOU WANT :-)
    [code]

    #include
    #include
    #include
    #include
    void extra1(void);
    void three1();
    void two1();
    void one1();

    int main(
    int NumberOfArguments, //to know how many strings user has typed
    char *Arguments[ ] //strings typed will be held in this
    )
    {
    int NotEOF = 1 ; // just to make sense of the while loop
    char InduvidualCharacter ='a'; //this will retirve character while copying
    FILE *FileToBeCopied ;
    FILE *FileToBeCopiedToo ;


    clrscr();

    if (NumberOfArguments!=3)
    {
    printf ("
    IMPROPER SYNTAX
    "
    "Syntax Is Like This

    "
    "CommandName CN
    "
    "FileNameForTheFileToBeCopied FNFTFTBC
    "
    "FileNameForTheFileToWhichItIsToBeCopiedToo FNFTFTBCT

    "
    "CN FNFTFTBC FNFTFTBCT
    "
    );

    printf ("

    Please Try Again");
    //exit(0);
    return 0 ;
    }


    FileToBeCopied = fopen(Arguments[1],
    "r" //file needs to be opened in read mode
    );

    if (FileToBeCopied==NULL)
    {

    clrscr();
    puts("CanNot Open Source File
    "
    "Could have done something
    "
    "about it if had MORE TIME
    "
    "Its My Time to SLEEP Now..
    "
    ) ;

    return 0 ;

    }

    FileToBeCopiedToo =fopen(Arguments[2],
    "w" //opens file in write mode
    );

    if (FileToBeCopiedToo==NULL)
    {

    clrscr();
    puts("CanNot Open Destination File
    "
    "Could have done something
    "
    "about it if had MORE TIME
    "
    "Its My Time to SLEEP TOo..
    "
    ) ;

    return 0 ;

    }

    while (NotEOF) //keeps on looping unless end of file encountered
    {
    InduvidualCharacter = fgetc(FileToBeCopied);

    if(InduvidualCharacter==EOF)
    {
    NotEOF=0; //this is not required it is only
    break ; //understand the sense of it.it does
    //nothing which makes sense!
    }

    fputc(InduvidualCharacter, //putting retieved characters to the destination
    FileToBeCopiedToo
    );
    }

    fclose(FileToBeCopied ); //closing after done
    fclose(FileToBeCopiedToo);
    return(0 );

    }

    /* extra information

    declaring Pointers
    to Structure FILE
    FILE *fp1,*fp2,*fp3,*fp4;

    for giving path we use \
    unlike in dos which is "";

    fp1=fopen("c:\windows\sc1.c","w+");
    fp2=fopen("sc2.c","w+") ;

    for closing opened files

    fclose(fp1);
    fclose(fp2);

    For Deleting Files

    remove("c:\windows\sc1.c");
    remove("sc2.c") ;
    */
    /*DesCripTion Of The Above ProgRAm
    whenever we want to write on a command pompt
    something for which a programm should start execution
    than that programms main() should have parameters in it
    to take our given command as Instruction For What That
    ProgRamm Has Been MAde For
    These Arguments variables Should Be Only Two In NUmber
    usually First One KEEps the count of the ParaMeters Passed
    Into the SEcond Argument Of THe FUncTIOn WHich IS GEnerally
    A char Pointer In Which MAkeSense Instructions Can Be LOaded
    Based On THese Instructions Programm Executes THe Desired
    OUput.NOw
    SInce it Involves FILe Opening THereFore
    WHen a FIle is Asked TO be OPened It is CHecked
    WHeather that Operation WAs SUccessful Or Not
    If not It will return NULL.WHich we can use to further
    make our prgramm Perform the needful.abort the Programm
    or do the needful to Mend the Problem.we choose to abort.
    Rest is Fairly SImple COmmands.fopen() takes Two Arguments
    as Parameters One The FIlepointer which would contain
    the name of the file to open and sencond how it needs to be
    opened in read mode write mode append mode.that informtion
    must be enclosed in " ".like
    Read ="r"
    write ="w"
    append="a"
    well u must know all this since you are already making an
    executable.now fgets()
    it takes only one argument and passes a charater from the file
    if succesful to the varialbe we want to hold the information
    in.when it gets the file for the first time it places control
    on the first item which might be anything inside the file
    it might be empty thing and then keep on advancing itself
    untill it reaches EOF.ofcourse for that it needs looping
    one from outside which we provide.incrementing to next item
    it does itself as many times we call it without closing the file
    it will keep on advancing.which is fairly simple. ++.
    fputc() takes two arguments as parameter and one of them is the
    induvidual character we want to write too the file
    and second ofcourse is a pointer to that file.
    same thing advancing the pointer takes place in it too unless we close
    the file.
    NOW I MUST GO AND EAT AND SLEEP IT IS PAST 12 IN NIGHT;
    typos now youu will understand why they happened;
    */


    [/code]
Sign In or Register to comment.