fgets problem

K

Keith Thompson

Alan Peake said:
Phil said:
So scrap "char*str;" and "str=f", and use "char str[20];" instead.

Thanks Phil, that solved the problem. Hadn't realised that char *str
doesn't point anywhere but char str[20] allocates space for the array.
Program now compiles without errors.

Let me recommend again that you take a look at the comp.lang.c FAQ,
<http://www.c-faq.com/>. Question 7.1 is particularly relevant, but
it wouldn't hurt to read the whole thing. (Note that the sample code
uses gets(), which should *never* be used.)
 
J

James Kuyper

Alan said:
(e-mail address removed) wrote: ....


Had no questions regarding toupper or getchar. Don't know how you got
that idea.

If he is right about Cunningham being a particularly devious kind of
troll, and if he is right about you being the same kind of troll, then
the line he refers could be intended to provoke such a discussion, even
though you didn't ask any explicit questions about it. The reasons why
it is wrong are subtle and complicated enough that you might reasonably
hope to keep several pedants like myself busy discussing the issue,
while keeping several trolls busy making fun of the pedants.

I don't know what to make of Bill Cunningham; I just know that there's
no point in joining any discussion thread he starts (which hasn't,
unfortunately, stopped me from doing so). I haven't seen enough messages
from you yet to justify reaching the conclusions that vippstar has reached.
 
A

Alan Peake

Phil Carmody wrote:

So scrap "char*str;" and "str=f", and use "char str[20];" instead.

Thanks Phil, that solved the problem. Hadn't realised that char *str
doesn't point anywhere but char str[20] allocates space for the array.
Program now compiles without errors.

Alan
 
A

Alan Peake

Maybe I'm just paranoid, but the last sentence gave him away I think.
He also doesn't have a real e-mail address.
I put kilspam in my email addres so all you need do is remove it and you
have my real address. Lots of people seem to do this to prevent
unsolicited mail.

The formatting is almost
excellent (in the first post) except the semicolons.
As for including "stdio.h" instead <stdio.h>, how can you miss
something like that when the other two headers use <>? He top-posted.
OK, mistake there.
He also did

char *str, c;

Then

toupper(c = getchar())
That's so subtly wrong and right (if c is changed to int) that I
honestly think he's trying to get you all to talk about getchar &
toupper. He's another Cunningham for christ's sake!

Had no questions regarding toupper or getchar. Don't know how you got
that idea.

I just don't know how you can get so many things wrong on 3 posts (and
I only mentioned _some_ of the things he got wrong). I imagine that
he'll probably continue asking such questions and posting totally
wrong code and you'll all continue wasting your time with him. Well,
have fun, but I think I'll pass.

Pass as you see fit but the questions were genuine and I've had enough
help to get the program working.
I'm not a professional programmer - never was - never will be. I just
write small C programs for my own use and it's been some time since I
did this so I've forgotten some things.

Alan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top