|
From: Michael C <jd...@ho...> - 2001-09-03 20:30:51
|
Hi,
I havn't programmed in C for a couple of years now, I've been concentrating
on C++.
I have forgotten a few things so I'm watching this group for input, and I've
been impressed by what I have seen.
I had a look at your code and spotted a few things:
1) For fopen() use "w+" as you need to read it as well.
2) Use ' fseek (fhandle, 0L, SEEK_SET);' to reposition the file to the
beginning for reading.
3) Dereference fhandle (*fhandle) in the fprintf() statement and this will
read in the string.
3) fprintf() and fscanf() do not move the file position and I can't remember
how to do this. So another call to fprintf() will not read the stringified
number on the next line. I thought I could use:
'fseek (fhandle, len, SEEK_CUR);' where len is the returned value
from a successful call to fprintf()
However, this doesn't work. Instead I prefer to use:
int c;
while ((c = fgetc (fhandle)) != EOF)
{
fputc (c, stdout);
}
Any comments?
Hope this helps.
Michael
----- Original Message -----
From: Johannes Pretorius <joh...@pr...>
To: <dev...@li...>
Sent: Monday, September 03, 2001 10:57 AM
Subject: Re: [Dev-C++] how to use strings
> Do you have some example code. for it seems you know what you want to do
> and have the right functions but something else is wrong. Please give a
> simple app or
> something that you wrote that gives this same problem and we can look at
> it. Futher we can
> only specilate as we dont really know the actual source of the problems
and
> the coding style or mixture being used
>
> Hope we can Help
> Johannes
>
>
> At 11:25 03/09/2001 +0200, you wrote:
> >hi, i am trying to convert a simple integer or byte or anything else
> >to a string in order to write to a file on disk.
> >
> >It does not work the way i did it for years with e.g. Microsoft C7.0
> >(Win3.1) and Visual C 6.0 (W32) - dont know why.
> >
> >a)
> >How do i convert a number liek eg int a = -105 to exactly ythis
> >string ?
> >
> >
> >b) Which function would be the best to write and read the correct
> >format fomr and to HD-Files ?
> >
> >I used to apply fprintf with formatted strings to read full lines of a
file
> >with known structure and directly obtained the desired variables.
> >
> >I copied the source code from a DOS prog and DEV C compiles
> >but reads only shit !
> >
> >Sorry for that, but I am going to get upset with this compiler.
> >
> >Does any body have an example wich directly works in DEV CPP
> >to find out where the problem is ?
> >
> >thanks in progress.
> >...............
> >
> >
> >_______________________________________________
> >Dev-cpp-users mailing list
> >Dev...@li...
> >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|