Thursday, July 9, 2009

How can i get run time inputs and output in C without using functions like scanf,gets,getchar ,printf etc?

It isn't clear what you mean by "etc", since there are a number of interpretations. For example you could mean stdio functions in the C library. Or you could mean any of the I/O functions.





We would also need to know what operating system you are running, since the answer can be different for various operating systems.





So, I'll need to be a bit vague to cover all the possibilities.





Assuming you are running an operating system (and are not writing an embedded C program), the OS will restrict access to all I/O devices. You will need to go through the OS, in other words make system calls.





There are library functions which make these calls (open, read, write), but if those are ruled out then you'd need to do what those functions do: place arguments in registers or on the stack (depending on the platform) and generate a trap to the OS system call handler. This is similar to a software interrupt, and causes the OS to begin running code which performs the I/O on your behalf.





Embedded C programs and those written for DOS can access their devices through memory maps, or in some cases special I/O machine instructions (like the x86 port instructions).


No comments:

Post a Comment