I want to design a function myscanf(*format,...)which can work as scanf() but without using any library function other than getchar().It should support string datatype also..Pls someone do it for me.plsssssssssss
I want to design a function myscanf(*format,...)which can work as scanf() but without using any library function other than getchar().It should support string datatype also..Pls someone do it for me.plsssssssssss
Unfortunately for you, we don't do homework. http://cboard.cprogramming.com/annou...t.php?f=4&a=39
What we will do is help you once you've made an attempt at a solution. Try the problem. If you're stuck, ask a more specific question.
One hint: you'll need to use va_start(), va_arg(), va_end(), and va_list from <stdarg.h> to code the variable arguments.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Those are macros.
I don't see how you're going to pass n amount of arguments to myscanf() without using a va_list.
> I want to design a function myscanf(*format,...)which can work as scanf() but without using any library function other than getchar().It should support string datatype also..Pls someone do it for me.plsssssssssss
You said you want to design it, then you ask someone else to do it for you.
There are various forms of this:
"I have the idea to try to X..."
"While eating biscuits and marmalade I suddenly realized that I could X..."
"I want to do X..."
"Suddenly the idea of X is quite stimulating..."
These are all code words for:
"I have been assigned X and it's due tomorrow."
People don't seem to understand how unbelievably obvious it is when they are requesting homework help. Asking for help on homework is allowed here -- how hard can it be to just follow the rules? Don't lie about whether it's homework, post your current attempts, ask specific questions, and don't expect us to write code for you.
That's four rules. How hard can it be to keep track of four rules?
Your instructor is going to be very unhappy with the result if he insists on such a stupid restriction. You need at least ungetc, so that you have the functionality to put some bytes back into the stream.I want to design a function myscanf(*format,...)which can work as scanf() but without using any library function other than getchar().
If you expect myscanf to work properly you need to understand that scanf does a lexical read, which basically means it keeps reading until:
* there is no more format
* there is no more data
* or the data doesn't match the format
The computer can only discern the last case after it has already read too far into the data. A further explanation is here.
You can still do your homework and get something close to scanf, but be smart and defend your grade.
Now now children, you all know that a little source code example goes a long way:
Now all you need to do is write scan_stream, and you're done! It's not too long either, my toy version is only about 600 lines from start to finish[1].Code:int myscanf ( const char *fmt, ... ) { va_list args; int rv; va_start ( args, fmt ); rv = scan_stream ( stdin, fmt, args ); va_end ( args ); return rv; }
[1] But that's without wide character support or C99 conformance
My best code is written with the delete key.