Formatted, your code would look like this:
Code:
# include <stdio. h>
# include <stdlib. h>
void main (int argc , char *argv[ ])
{
FILE *in , out ;
char ch ;
clrscr() ;
if (argc!=3)
{
printf ("you forget enter file name \n ") ;
exit(1) ;
}
in = fopen (argv[1] , "wb") ;
if (in = = NULL)
{
printf ("cannot open (first) output file\n ");
exit (1) ;
}
do
{
ch = getchar() ;
putc(ch , in) ;
} while (ch ! = '.') ;
fclose(in) ;
in = fopen (argv[1] , "rb") ;
if (in = = NULL)
{
printf ("cannot open input file \n") ;
exit(1) ;
}
out = fopen (argv[2] , "wb") ;
if (out = = NULL)
{
printf ("cannot open output file \n ") ;
exit(1) ;
}
ch = getc(in) ;
while (!feof (in))
{
putc(ch , out) ;
ch = getc(in) ;
}
fclose(in) ;
fclose(out) ;
}
It is all frakked up with all kinds of extraneous spaces. Compiling with MinGW gcc, I get:
C:TEST>gcc -Wall physics7.c
physics7.c:1: stdio. h: No such file or directory
physics7.c:2: stdlib. h: No such file or directory
C:TEST>
You should have gotten the same errors. There exist no files by those names (ie, with the ". h" extension), but rather the files stdio.h and stdlib.h do exist (ie, with the ".h" extension; notice the removal of that extraneous space). And frankly, I'm surprised that the compiler didn't complain about your "# include" instead of #include.
You should have been able to correct those errors immediately to get a shipload of other errors and warnings:
C:\otros\pc14402\dcw\PROJECTS\TEST>gcc -Wall physics7.c
physics7.c:5: warning: return type of `main' is not `int'
physics7.c: In function `main':
physics7.c:9: warning: implicit declaration of function `clrscr'
physics7.c:17: parse error before `='
physics7.c:7: warning: unused variable `ch'
physics7.c:6: warning: unused variable `out'
physics7.c: At top level:
physics7.c:22: parse error before `do'
physics7.c:25: warning: type defaults to `int' in declaration of `putc'
physics7.c:25: warning: parameter names (without types) in function declaration
physics7.c:25: warning: data definition has no type or storage class
physics7.c:26: parse error before `}'
physics7.c:27: warning: type defaults to `int' in declaration of `fclose'
physics7.c:27: warning: parameter names (without types) in function declaration
physics7.c:27: warning: data definition has no type or storage class
physics7.c:29: warning: type defaults to `int' in declaration of `in'
physics7.c:29: `argv' undeclared here (not in a function)
physics7.c:29: warning: initialization makes integer from pointer without a cast
physics7.c:29: initializer element is not constant
physics7.c:29: warning: data definition has no type or storage class
physics7.c:30: parse error before `if'
physics7.c:33: parse error before `1'
physics7.c:33: warning: type defaults to `int' in declaration of `exit'
physics7.c:33: conflicting types for `exit'
c:/dev-cpp/bin/../lib/gcc-lib/mingw32/2.95.3-6/../../../../include/stdlib.h:325: previous declaration of `exit'
physics7.c:33: warning: data definition has no type or storage class
physics7.c:35: warning: type defaults to `int' in declaration of `out'
physics7.c:35: `argv' undeclared here (not in a function)
physics7.c:35: warning: initialization makes integer from pointer without a cast
physics7.c:35: initializer element is not constant
physics7.c:35: warning: data definition has no type or storage class
physics7.c:36: parse error before `if'
physics7.c:39: parse error before `1'
physics7.c:39: warning: type defaults to `int' in declaration of `exit'
physics7.c:39: warning: data definition has no type or storage class
physics7.c:41: warning: type defaults to `int' in declaration of `ch'
physics7.c:41: warning: passing arg 1 of `getc' makes pointer from integer without a cast
physics7.c:41: initializer element is not constant
physics7.c:41: warning: data definition has no type or storage class
physics7.c:42: parse error before `while'
physics7.c:45: warning: type defaults to `int' in declaration of `ch'
physics7.c:45: redefinition of `ch'
physics7.c:41: `ch' previously defined here
physics7.c:45: warning: passing arg 1 of `getc' makes pointer from integer without a cast
physics7.c:45: initializer element is not constant
physics7.c:45: warning: data definition has no type or storage class
physics7.c:46: parse error before `}'
physics7.c:47: warning: type defaults to `int' in declaration of `fclose'
physics7.c:47: warning: parameter names (without types) in function declaration
physics7.c:47: warning: data definition has no type or storage class
physics7.c:48: warning: type defaults to `int' in declaration of `fclose'
physics7.c:48: warning: parameter names (without types) in function declaration
physics7.c:48: warning: data definition has no type or storage class
physics7.c:49: parse error before `}'
C:TEST>
A few things for you to do to clean that up:
1. Before you can use a standard library function, you must #include its header file. Read the documentation for exit() in order to see what its header file is. The same goes for clrscr(), which needs the conio.h header file.
2. The test for equality is with "==", not with "= =". Why did you stick those frakking stupid spaces in there like that? Correct it! And do the same for "! =" while you're at it.
Each error message and warning gives you the line number where the error occurs. Use that information to go to that offending line, see what's wrong with it, and correct it. Do that for each and every error and warning.
You cannot do anything else until your code compiles cleaning and your code cannot be said to compile cleanly until it compiles with no errors or warnings. Never ignore warnings! Warnings are much more important than errors.
After you have made all the corrections, post your code, properly indented and using code tags. If it is not doing what you expect it to be doing, then tell us what you expect and what it's doing instead. Again, we are not mind-readers.
PS
A lot of the errors and warnings were because the compiler was massively confused by your errors described in #2 above.
Look at this declaration:
FILE *in , out ;
The file I/O functions expect to work with a FILE pointer (ie, a FILE* ). Instead, you declare out as a FILE, not as a FILE pointer, and then try to use it as a FILE pointer which is wrong.
Correct that.