fgets() equivalent?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > fgets() equivalent?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    fgets() equivalent?  
J de Boyne Pollard


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-01-07 12:24 AM

HS> fgets() is standard in C file I/O.
HS>
HS> The only issue you need to pay attention too, is
HS> RAW (binary) vs COOK mode. It will relate the
HS> EOL (end of line) definitions of MS-DOS
HS> (<CRL><LR> ) vs Unix (<LF> ).  Depending on
HS> your application that may or may no pertain.
HS> [...]
HS> More examples:
HS>
HS>      // opens the file in text mode, cooked.
HS>      FILE *fvt = fopen("crap1.txt","wt");
HS>      fprintf(fvt,"%s\n",string);   <-- note \n
HS>      fclose(fvt);
HS>
HS>      // opens the file in binary mode, raw
HS>      FILE *fvb = fopen("crap2.txt","wb");
HS>      fprintf(fvb,"%s\r\n",string);  <-- note \r\n
HS>      fclose(fvb);

TR> This is a handy definition, but it is NOT CORRECT.
TR> Cooked mode in a Unix terminal program means
TR> "line at a time".  The program cannot read anything
TR> until the user has pressed Return or Enter.  Raw
TR> mode means "character at a time".  Each keypress
TR> is returned to the program as soon as it is
TR> transmitted.

HS> I would like to see an official definition of that.  By
HS> your definition, TELNET and all telecommunication
HS> programs in the annals of computers is both RAW
HS> and COOKED.  [...]

If you want to see an official definition then run, do not walk, to
your nearest copy of the _Single UNIX (R) Specification, Version 2_ and
read about canonical and non-canonical input modes, in the General
Terminal Interface chapter of the XBD section.  Then read the
Interface Overview of the XCURSES section.

TR> The raw vs cooked distinction in Unix is VERY
TR> different from the binary vs text distinction in
TR> MS-DOS.  As others have tried to point out,
TR> raw vs cooked mode in Unix applies ONLY to
TR> terminals.  It has no meaning for text files.

HS> Not quite and its probably not worth your time
HS> and mine, debating it.
HS> COOK vs RAW is what it is,  COOK is a
HS> translation of some kind being done,
HS> RAW means its no translation.
HS> [...]
HS> In terminal servers, hitting <ENTER>
HS> could be that the CLIENT software
HS> will send the <CR> only or <CR><LF>
HS> pair. [...]

You are still, as M. Roberts and others have pointed out, confusing
text file newline conventions (and C language stream modes) with Unix
terminal input processing modes.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:27 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register