home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!rational.com!stripe!rmartin
- From: rmartin@stripe.Rational.COM (Bob Martin)
- Subject: Re: HELP with File I/O
- Message-ID: <rmartin.728089285@stripe>
- Sender: news@rational.com
- Organization: Rational
- References: <C1DI47.JJt@well.sf.ca.us>
- Date: Tue, 26 Jan 1993 23:01:25 GMT
- Lines: 56
-
- andras@well.sf.ca.us (Andrew Raskin) writes:
-
-
- |arsen@mindvox.phantom.com (Arsen Pereymer) writes:
-
- |> Hi everyone... I am having some trouble with file I/O
-
- Perhaps, but there is a critical flaw which may be your problem...
-
- |> #include<stdio.h>
- |> #include<conio.h>
- |> #include<string.h>
- |> #include<malloc.h>
- |> #include<dos.h>
- |> main()
- |> char *line;
- |> FILE *in, *out, *read; int i=0;
- |> clrscr();
- |> in = fopen("c:\\autoexec.bat","r");
- |> out = fopen("\\autoexec.dat","wb");
- |> for(i = 0;i <= 1;i++) {
- |> line = (char *) malloc(sizeof(line));
- ^^^^^^^^^^^^
- =======================================================
-
- This is not doing what you think it is. What is sizeof(line)? It is
- the size of the variable line. This variable is a char*, thus the
- size is the size of a pointer. Probably 4, perhaps as small as 2.
- You are certainly going to be reading in more than 2 or 4 bytes, so it
- may very well be that your are corrupting the heap. If fprintf is
- using the heap for its buffer, you could be corrupting the i/o buffer.
- This may be why the file appears unreadable....
-
- |> fscanf(in,"%s",line);
- |> fprintf(out,"%s",&line);
- |> free(line); }
- |> fclose(in);
- |> fclose(out); char *r;
- |> read = fopen("\\autoexec.dat","rb");
- |> fscanf(read,"%s",&r);
- |> printf("\nName : %s",r);
- |> fclose(read);
- |> getch();
- |> return 0;
- |>
-
- |> Any suggestions? Thanks in advance....
- |>
-
-
-
- --
- Robert Martin | Design Consulting | Training courses offered:
- R. C. M. Consulting | rmartin@rational.com | Object Oriented Analysis
- 2080 Cranbrook Rd. | Tel: (708) 918-1004 | Object Oriented Design
- Green Oaks, Il 60048| Fax: (708) 918-1023 | C++
-