Re: problems with CR (carriage return) and LF (line feed )
From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 12/08/03
- Next message: Andy: "Re: [FAQ] Re: 32-bit IEEE float multiplication"
- Previous message: Randy Howard: "Re: ANSI clear screen [MS & Borland]"
- In reply to: Andrew: "problems with CR (carriage return) and LF (line feed )"
- Next in thread: those who know me have no need of my name: "Re: problems with CR (carriage return) and LF (line feed )"
- Reply: those who know me have no need of my name: "Re: problems with CR (carriage return) and LF (line feed )"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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!
- Next message: Andy: "Re: [FAQ] Re: 32-bit IEEE float multiplication"
- Previous message: Randy Howard: "Re: ANSI clear screen [MS & Borland]"
- In reply to: Andrew: "problems with CR (carriage return) and LF (line feed )"
- Next in thread: those who know me have no need of my name: "Re: problems with CR (carriage return) and LF (line feed )"
- Reply: those who know me have no need of my name: "Re: problems with CR (carriage return) and LF (line feed )"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|