what I want is if the first file has the following data
 
1
2
3
4
5
6
7
8
9
 
I want the following data to be copied to the other program
 
2
4
6
8
 
i.e copy the even lines

--- On Tue, 8/12/09, Peter Nilsson <[email protected]> wrote:


From: Peter Nilsson <[email protected]>
Subject: [c-prog] Re: samar
To: [email protected]
Date: Tuesday, 8 December, 2009, 4:29 AM


  



samar aseeri <samaraseeri@ ...> wrote:
Subject: samar

Please make your subject line describe the nature of your
post. Your name is far from a good description of the content.

> the below attached program uses the argument command line
> the copy a file to another file. my question is what can I
> change in   the program to make only part of the first file
> be copied to the second.

Before you change the code, you first have to decide what
part you want to return. Is it a number of characters, a
a number of words, a numbr of lines, only every third
palindrome, ... what?

> #include<stdio. h>
> int main(int argc, char *argv[])
> {
>   FILE *inFilePtr;   /*input file pointer*/
>   FILE *outFilePtr;   /*output fole pointer*/
>   int c,i;
>   /*check number of command-line arguments */
>   if(argc != 3){
>     printf("Usage: mycopy infile outfile\n"); } /*end if*/

These messages are better off directed to stderr.

>     else /*if input file can be opened*/
>       {
>         if((inFilePtr= fopen(argv[ 1],"r"))! =NULL)  /*if input
> file can be opened*/
>          { if((outFilePtr =fopen(argv[ 2], "w")) != NULL)
> /*if output file can be opened*/
>             {while((c = fgetc(inFilePtr) ) !=EOF) /*read and
> output characters*/

That's your core loop. What you need is...

while (...keep going condition... && (c = fgetc(inFilePtr) ) !=EOF)

>               {
>             fputc(c,outFilePtr) ;}/*end while*/
>           }/*end if*/
>         else /*output file could not be opened*/
>           {printf("File\ "%s\" could not be opened\n", argv[2]);
>           } /*end else*/
>       }/*end if*/
>     else /*input file could not be opened*/
>     {  printf("File\ "%s\" coulk not be opened\n", argv[1]);}
>  /*end else*/

ITYM could, not coulk.

>               } /*end else*/
>      return 0; /*indicates successful termination* /

Which would be an ironic thing to return if it couldn't open
either stream.

>      }/*end main*/

-- 
Peter









      New Email addresses available on Yahoo!
Get the Email name you&#39;ve always wanted on the new @ymail and @rocketmail. 
Hurry before someone else does!
http://mail.promotions.yahoo.com/newdomains/aa/

[Non-text portions of this message have been removed]

Reply via email to