ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i am trying to understand a c code for the arguments in C but i get a bit confused....i will be pleased if you answer me some questions for the code....
1. why in function myRead the programmer uses two files as a parameter of the function???i only have one file to open....
2.while(argc==1) the parameters of the function is myread(stdin,stdout) but in else is myread(fp,stdout)...why this is different????
3. if i want to read from a file...can i always use the function myread as a standard function for read from a file???
The function is defined such that it gets characters from one file and the sends them (put) to another file. That is why there are two arguments.
When the function is called, you have to tell it the source and destination. In one case, it is simply "stdin" and "stdout" (which I assume are defined in stdio.h). In the other case, "fp" is used instead of "stdin". Which option gets used is determined by the number of arguments sent to main().
For context, please tell us where you are in your studies--eg is this your first class in C?
Last edited by pixellany; 10-31-2009 at 08:37 AM.
Reason: typo
i know what does the arguments means but i get a bit confused...thanks for your help....
You need to say what you get confused about, because how else will we know?
Quote:
Originally Posted by pixellany
For starters, where did you get this code?
The function is defined such that it gets characters from one file and the sends them "put" to another file. That is why there are two arguments.
When the function is called, you have to tell it the source and destination. In one case, it is simply "stdin" and "stdout" (which I assume are defined in stdio.h). In the other case, "fp" is used instead of "stdin". Which option gets used is determined by the number of arguments sent to main().
I suppose you and I have different approaches to "teaching". I prefer to gauge what they know and get them to think a bit .
I suppose you and I have different approaches to "teaching". I prefer to gauge what they know and get them to think a bit .
I'm making no attempt at teaching. If I were, there would be a very different dialog.
I make quick judgement calls about the appropriate response to a question. I this case, it was obviously homework, but there was also evidence of prior effort. I posted what seemed to me to be the best way to get OP going in the right direction......YMMV
this means that if there is not any file in command line the only elements excists is the name of the programme e.g. ./programme ,why we read from a file....while the file does not excists....??
You lost me......That code fragment says that if the argument count is 1, then execute "MyRead" using stdin and stdout. In that case it is not necessarily reading from a file, but from whatever stdin has be defined to be----ie typically the keyboard.
As I requested previously, please tell us more about the context of your questions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.