Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #6575

Re: writing and copying a text file

From Ike Naar <ike@sverige.freeshell.org>
Newsgroups comp.lang.c
Subject Re: writing and copying a text file
Date 2011-06-21 21:56 +0000
Organization A noiseless patient Spider
Message-ID <slrn3vfsj024sq.1tm.ike@sverige.freeshell.org> (permalink)
References <41ff0881-2f1b-4462-8b26-28ca698b180f@a11g2000yqm.googlegroups.com>

Show all headers | View raw


On 2011-06-21, lolueec <marvee1981@gmail.com> wrote:
> I'm new to C language and I'm trying to copy and write a text file.
> Here is my code - can some one explain why it is not working?

It would be helpful if you could be more specific.
In what way is it ``not working''?

Anyway, here are a few obvious problems:

> #include <stdio.h>
>
> int main()

Better: main(void)

> {
> int x;
> FILE *handle1, *handle2;
>
> handle1=fopen("a text file","r+);

Why "r+" instead of plain "r" ?
Also note that in your code the closing double-qoute after "r+ is missing.
And it's prudent to check whether fopen succeeded.

> handle2=fopen("a text file to write","w+");

Why "w+" instead of plain "w" ?
Again, check whether fopen succeeded.

> while( (x=fgetc(handle1) != EOF){

The parentheses don't match; most likely one is missing after ``handle1)''

> fputc(x,handle2); // write to the file
> }
>
> fclose(handle1);
> fclose(handle2);
>
> }

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

writing and copying a text file lolueec <marvee1981@gmail.com> - 2011-06-21 14:22 -0700
  Re: writing and copying a text file John Gordon <gordon@panix.com> - 2011-06-21 21:42 +0000
  Re: writing and copying a text file Ike Naar <ike@sverige.freeshell.org> - 2011-06-21 21:56 +0000
    Re: writing and copying a text file Keith Thompson <kst-u@mib.org> - 2011-06-21 15:52 -0700
      Re: writing and copying a text file Ike Naar <ike@sverige.freeshell.org> - 2011-06-22 06:33 +0000
  Re: writing and copying a text file Shao Miller <sha0.miller@gmail.com> - 2011-06-21 18:02 -0500
  Re: writing and copying a text file Mark Bluemel <mark_bluemel@pobox.com> - 2011-06-22 08:30 +0100
  Re: writing and copying a text file Vinicio Flores <vfloreshdz@gmail.com> - 2011-07-03 20:32 -0600
    Re: writing and copying a text file lawrence.jones@siemens.com - 2011-07-04 12:27 -0400

csiph-web