Re: undefined behaviour?
"santosh" <santosh.k83@gm ail.com> writes:
[color=blue]
> Jordan Abel wrote:[color=green]
>> On 2005-12-15, santosh <santosh.k83@gm ail.com> wrote:[color=darkred]
>> >> char *file_name = "t1.txt";
>> > An uninitialised pointer is being used here.[/color]
>>
>> The line you are responding to is a declaration, and, moreover, one with
>> an initializer.
>>
>> You claim that on your implementation the program crashes on that line.
>> Either you're lying, or you have a very crappy [and non-conforming]
>> implementation.[/color]
>
> Your right. I'm sorry. It was an incredible oversight on my part.
>
> That being said, the code as was posted did crash over here.
> The compiler is gcc (mingw).
> After I introduced error checking for each function call I found that
> the
> first error was with foen().[/color]
Well that does not mean that the code as given was invalid
[color=blue]
> I modified "r+" to "w+" which succeeded, but then ungetc() returned
> EOF.[/color]
That's interesting and I think that should not happen, even if you use
"r+".[color=blue]
> I corrected that by inserting a 'fflush(pf)' before calling
> ungetc().[/color]
I'd argue this is the real problem.
The system as used her has worked fine but baild out on the fclose at
the end. After insering the fflush here this was gone and the result
were as expected.
[color=blue]
> After I changed 'ch' from char to int the program finally executed as
> it[/color]
I don't think this is really a problem.[color=blue]
> should. The contents of the file after running the code is:[/color]
Can't tell I did not care about the content just the fputs + ungetc
stuff. However thanks for taking the time checking all this "stuff"
Regards
Friedrich
--
Please remove just-for-news- to reply via e-mail.
"santosh" <santosh.k83@gm ail.com> writes:
[color=blue]
> Jordan Abel wrote:[color=green]
>> On 2005-12-15, santosh <santosh.k83@gm ail.com> wrote:[color=darkred]
>> >> char *file_name = "t1.txt";
>> > An uninitialised pointer is being used here.[/color]
>>
>> The line you are responding to is a declaration, and, moreover, one with
>> an initializer.
>>
>> You claim that on your implementation the program crashes on that line.
>> Either you're lying, or you have a very crappy [and non-conforming]
>> implementation.[/color]
>
> Your right. I'm sorry. It was an incredible oversight on my part.
>
> That being said, the code as was posted did crash over here.
> The compiler is gcc (mingw).
> After I introduced error checking for each function call I found that
> the
> first error was with foen().[/color]
Well that does not mean that the code as given was invalid
[color=blue]
> I modified "r+" to "w+" which succeeded, but then ungetc() returned
> EOF.[/color]
That's interesting and I think that should not happen, even if you use
"r+".[color=blue]
> I corrected that by inserting a 'fflush(pf)' before calling
> ungetc().[/color]
I'd argue this is the real problem.
The system as used her has worked fine but baild out on the fclose at
the end. After insering the fflush here this was gone and the result
were as expected.
[color=blue]
> After I changed 'ch' from char to int the program finally executed as
> it[/color]
I don't think this is really a problem.[color=blue]
> should. The contents of the file after running the code is:[/color]
Can't tell I did not care about the content just the fputs + ungetc
stuff. However thanks for taking the time checking all this "stuff"
Regards
Friedrich
--
Please remove just-for-news- to reply via e-mail.
Comment