Re: problems with CR (carriage return) and LF (line feed )

From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 12/08/03


Date: Mon, 08 Dec 2003 03:12:45 GMT

Andrew wrote:
>
> I have created a program that downloads a web page and then performs
> some text processing on it . The problem is in the text processing ,
> every line (in the downloaded txt file ) ends with a strange symbol
> which is the carriage return and the line feed . ( Hex values 0D and
> 0A ). How are these values represented in C ??? . For istance for
> every character I read from the file i want the function to ignore it
> . for example :

I have taken the liberty of reformating your code so I can clearly
indicate suggested changes (which are no longer quoted lines).
>
> ...................................................
>
> while ((c = fgetc(fp) ) != EOF ) {
> switch(c) {
> case '<' : tagFlag = true;
> cont = true;
> i = 0;
> if (getvalue == 1) {
> getvalue = 0;
> string_found = false ;
> }
> break;
>
> case '>' : tagFlag=false;
> break;
>
> /* case <<<<<< What should i put here ?????? */
   case '\n':
   case '\r': break;
>
> default : if ( (string_found == true) ) {
> if (tagFlag == false ) {
> getvalue = 1;
> printf("%c \n",c);
> }
> }
> else if ( (string_found == false)) {
> if ( (tagFlag == false) && (cont == true)) {
> if (c == target[i]) {
> if (i == (target.GetLen()-1) ) {
> times_found++;
> string_found = true;
> }
> else {
> i++;
> cont = true;
> }
> }
> }
> }
> break;

> } /* switch */
> } /* while */

Excessive vertical spacing is just as harmful to comprehensibility
as the lack of breaks. Note that braces around the individual
cases are useless and confusing, as code normally simply executes
in order in the absence of a break.

I believe that the standards for HTML specify that those lines end
in \r\n, so the solution should be portable. However I am not
sure of this. You may want to inject a blank, which you can
probably do by replacing the "break" with "c = ' '" and falling
through. Other than this I am making no allegations about the
accuracy of the code.

-- 
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!


Relevant Pages

  • Has Andrew Bordens reputation suffered as the result of misandry?
    ... The Journal of Lizzie Borden ... Has Andrew Borden's reputation suffered as the result of misandry? ... it-for the sake of making money. ... Frank Spiering in Lizzie defines Andrew's character in terms of his ...
    (soc.men)
  • Re: regular expression help
    ... Andrew, thank you so much for your help. ... Joe Blow, 123 Main St ... You use paired parentheses to capture. ... I need to capture a character sequence to do something with it. ...
    (microsoft.public.windows.server.scripting)
  • Re: URL_fetcher
    ... Andrew wrote: ... not made any real effort at packaging stuff up to be user friendly. ... downloads, ideally with sensible ReadMe files and all of the other niceties. ...
    (comp.sys.acorn.apps)
  • Re: favorite companion
    ... Andrew wrote: ... lalla ward mmm mmm. ... Sarah Jane does it for me every time - a good strong character, ...
    (rec.arts.drwho)
  • Re: [SLE] "fetchnvidia" script problem
    ... On Wednesday 30 June 2004 13:57, Andrew wrote: ... > I've just downloaded the latest fetchnvidia script for 9.1 from SUSE.com ... It looks like a display error, but I can switch back to the ... > downloads the 4496 version of the drivers. ...
    (SuSE)