this coding is about copy one existing file into other file

but it can't do so throught the command line arg. what is

the solution....?

#include<stdio.h>

	#include<conio.h>

	#include<stdlib.h>

	void main(char *argv[])
	{

		FILE *fp1,*fp2;
		char c;
		int i;

		clrscr();

		fp1=fopen(argv[1],"r");

		rewind(fp1);

		fp2=fopen(argv[2],"w");


		if(fp1==NULL)
		{

			printf("Source File is Not Exist");
			exit(0);

		}



		while((c=getc(fp1))!=EOF)
		{


			putc(c,fp2);

			printf("%c",c);


		}

		fclose(fp1);

		fclose(fp2);

	getch();

	}
Salem commented: 10+ posts, no code tags - cookie time :( -5

Recommended Answers

All 3 Replies

1. Wrong main prototype. Must be:

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

2. fgetc returns int, declare c as int.
3. No need in rewind(fp1). Test fp1 == 0 befory any ops with opened file.
4. Test argc == 3 (argv[0] - program name, argv[1] and argv[2] - file names).
5. You can't copy binary file in text mode. To open in binary mode use "rb" and "wb" open mode arguments.

1. Wrong main prototype. Must be:

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

2. fgetc returns int, declare c as int.
3. No need in rewind(fp1). Test fp1 == 0 befory any ops with opened file.
4. Test argc == 3 (argv[0] - program name, argv[1] and argv[2] - file names).
5. You can't copy binary file in text mode. To open in binary mode use "rb" and "wb" open mode arguments.

i have tried it but there is no change i got the same massage

here, getc() function used for get the value from existing file ,

character by character & put into new file

( which is given during run time )

character by character

can u pls send me more detail....?

>>i have tried it but there is no change i got the same massage
What error message -- you never said what that was. Post code and make sure main() is declared like ArkM posted.

Post code if you need more help. And if you are trying to copy binary files then you have to open the files in binary mode, also as previously suggested.

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.