LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Sending data to a command using C (https://www.linuxquestions.org/questions/programming-9/sending-data-to-a-command-using-c-562986/)

gregorian 06-26-2007 10:15 PM

Another improvement: Instead of using this:
fputc('y',pipe);
fputc(10,pipe);

We can use:
fputs("y\r",pipe);

PatrickNew 06-26-2007 10:20 PM

On that note, we could use
Code:

fputs("y\n");
as '/n' is "newline" while '/r' is return. I'm unsure, but I think the '/n' is more portable.

gregorian 06-26-2007 11:56 PM

I tried \n. It works. Is there any difference between \n and \r ?

P.S. You're supposed to use \ and not /

PatrickNew 06-27-2007 12:04 AM

thanks, the "\" is corrected.

I'm quite unsure about this, but I think the \r is a carriage return, while '\n' is whatever combination of carriage return and line feed constitutes a line delimiter on the current platform.

chrism01 06-27-2007 01:06 AM

On MS it it's CRLF (aka \r\n), whereas *nix systems just use LF (\n), hence the issue if you edit text on eg
MS Notepad and upload in binary mode to *nix.
Just to be different, Mac uses CR, see http://www.websiterepairguy.com/articles/os/crlf.html

gregorian 06-27-2007 02:30 AM

I read the article, but I still don't understand the difference between a LINE FEED and a CARRIAGE RETURN. What should I use in my program? \n or \r ?

Also, how do you send combinations like Ctrl-C, Shift-F1 etc. through the program?

PatrickNew 06-27-2007 10:04 PM

On a typewriter, at the end of line you had to do two things - move the paper up one line and slide back over the the left. Moving up a line is the line feed and moving back to the left is the carriage return. Many early computer monitors were essentially remote type writers, so a special character was created for these. However, UNIX systems, Linux included, use only the line feed. DOS systems, like windows, use both. Some other systems use only the carriage return. Using '\n' ensures that your program uses the correct character(s) for the system it is on.

chrism01 06-28-2007 02:14 AM

Code:


Also, how do you send combinations like Ctrl-C, Shift-F1 etc. through the program?

If you mean what I think, store the codes as the ASCII Decimal or Hex values until you need them : http://www.cdrummond.qc.ca/cegep/inf...iles/ascii.htm

gregorian 06-28-2007 06:26 AM

I went through the table. Where are the "Ctrl", "Shift", "F1" etc. characters?. How do I send combinations of these special characters? If I want to send "tysdf" followed by the Enter key, I would write fputs("tysdf\r");. What do I do if I want to send Ctrl-F1 ?

gregorian 06-30-2007 08:07 AM

Does anyone know how these are sent?


All times are GMT -5. The time now is 03:25 AM.