fpurge/fflush

N

Nick Keighley

I just got another quick question, it isn't anything about this.. But
anyway, i just started programming (which you would have figured out),
and how would the perfect start be for me? C isn't too difficult to
me, but maybe there were another language which would be better to
learn first?

If you are finding C ok you might as well stick with it. It does
require more care than other languages and doesn't hold your hand so
much. If you want chunks of memory where you don't kow the size until
run-time then you have to manage this yourself (not too onerous);
whilst
other languages would do it for you. If you want such a language then
I
quite like Python.

I mean.. Where would you start hacking/programming if you
could choose to start your life over?

Python I suppose. It would be nice to start with something that is
reasonably structured and regular (which rules perl out..) and it's
nice for beginners to be able to *do* something with a tangible
outcome.
So a graphics interface is nice.
 
P

Phil Carmody

Seebs said:
Thanks for the answers.
All the codes you guys replied works!
Any way, i would like to know how the cryptic code (every command)
works that io_x posted, if you dont mind to explain:
#include <stdio.h>
int flush(FILE* pf, int cx)
{int c;
if(cx=='\n'|| cx==EOF)
return cx;
while((c=getc(pf))!=EOF && c!='\n');
return c;
}

This is a very odd design. It starts with the next character in a stream,
then loops through the stream until it gets either EOF or a newline character.
The intent is to discard the buffer. I don't see why it has a second
argument, though.
if(a>b) printf("\'%c\'[%d] is greater than \'%c\'[%d]\n",
(char)a, a, (char)b, b);

This is pure cargo cult. The backslashes on the ' are unnecessary and
confusing. The casts to (char) are useless; all that happens is the
values get promoted straight back to int anyway.

Not necessarily - there's possibly an implementation-defined step
on the (unsigned char within an) int -> char conversion (6.3.1.3#3).
Quite what choices are available to the implementation isn't clear.
The layout of trying
to arrange the arguments under their format controls is interesting,

Perhaps 'cute'? (Which, like 'interesting' is mostly an insult.)
but
I wouldn't do it. The arrangement of the printf after the if is... Well,
again, I sure wouldn't do it. I would find this code hard to read.

Indeed.

Phil
 

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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top