R
RSoIsCaIrLiIoA
until a poor newbie can build a better function than sscanf and fgets
scanf("%s", string) is like gets(string)
scanf("%s", string) is like gets(string)
until a poor newbie can build a better function than sscanf and fgets
scanf("%s", string) is like gets(string)
RSoIsCaIrLiIoA said:
That is, it's an extremely bad idea, compared to fgets and parsing it
yourself (or, if you're careful, using sscanf).
The fgets function itself is not as good as a customised input routine that
does precisely what the experienced and knowledgeable programmer requires
but, in the absence of such a routine, fgets is your best bet every time
(except, perhaps, on a few occasions where getc might be considered more
appropriate).
than if you use "%s" in sscanf is the same
no inscanf is should not allow to use "%s" **never** only
this is Newfgets that is like fgets but
int Newfgets(char *buffer, int size, FILE* pf);
if a=Newfgets(buffer, size,pf);
if the old fgets return not NULL => Newfgets return the len of written
buffer in a
if the old fgets return NULL => Newfgets return the len of written
buffer in -a
Richard said:RSoIsCaIrLiIoA said:
Well, no, because what you can do is capture the string using
fgets, as I suggested, in which case you /know/ how long the
string is, so you can allocate storage for that length + 1, and
*then* use %s in sscanf with perfect safety.
Why are you feeding the troll?
Richard said:CBFalconer said:
I'm correcting misinformation. Your opinion of its source is noted,
but it seemed to me that the subject under discussion was worth
discussing. When a subject seems to me to be worth discussing, I
reserve the right to discuss it.
However considering the record of this
particular troll I consider any response to be pointless.
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.