English 中文(简体)
B. 在吉大港山区应对措施中找到新路线
原标题:Finding newlines in HTTP responses

我目前有一个基本上从网页上读到html的方案。 在寄送网站服务器后,我回了回复,我在那里用空话读了袖珍:

FILE *webpage = fdopen(socket, "r");

then I have a loop that uses fgets to get each line and then print them to a file:

while(!feof(webpage)){
    fgets(newline, 1000, webpage);
    fprintf ...
}

该方案的这一部分进行罚款。

HTTP/1.1 200 OK^M
Date: Fri, 18 Nov 2011 04:42:40 GMT^M
Server: Apache/2.2.14^M
Accept-Ranges: bytes^M
Cache-Control: max-age=0^M
Expires: Fri, 18 Nov 2011 04:42:40 GMT^M
Vary: Accept-Encoding^M
Content-Length: 345235^M
Connection: close^M
Content-Type: text/html^M
X-Pad: avoid browser bug^M
^M
<html lang="en">
<head>
...

I want to find this newline that is right under xpad, and insert something right when this newline is found (basically do something right after the headers are printed. However, I m not sure how to find the line, or what the ^Ms are for.

目前,我正在做像样的尝试。

if(newline == "
"){
   ... 
}

or just " ", and it doesn t work. I think its got something to do with the ^M but I m not sure.

感谢!

最佳回答

^M (Ctrl+M) is the ascii carrige return, I believe you can search for just and not

I think ideally you want to do a regex check and check for a new line character at the beginning for the line ie ^ alternativly you could just check the .length and see if it contains a new line if its 0. You just want to make sure you don t catch any false positves.

问题回答

对于头盔来说,吉大港湾中心使用运输回程+线上岸的配对机标示线终点——因此你认为是运输回报的特性。 如果特定申请允许,在主人之后,在身体上终止的界线可能有所不同。

头盔的终点是一条空线,因此,这条线上的第一个特征是运输的返回(甚至其他白色空间也可以出现在运输前面)。 因此,你第一次发现一线是头号,你发现头部已经结束;其余所有线都是身体的一部分。

if(newline == " "){ doesn t work because you can t compare strings that way -- you re checking the address pointed to by newline for equality with the address of the string literal " ", which will be false even if the characters in newline match. strcmp() or strncmp() would work, but since it s only two characters you may as well compare them individually (might even be faster). It s also highly unlikely you d get outside of a line ending, so you re probably safe just checking for for that.

如果<条码>buf足够大,足以控制任何条形,则以下大致概述需要做些什么(一种办法,至少是):

char buf[BUFSZ];
// ...
while( fgets( buf, BUFSZ, sock ) ) {
  if (buf[0] ==  
 ) {  // or (buf[0] ==  
  && buf[1] ==  
 ) to be strict
    // DO STUFF for end of header section
    break;
  } else {
    // DO STUFF for a header line
  }
}
// if needed, get rest of document
while( fgets( buf, BUFSZ, sock ) ) {
  // DO STUFF for a body line
} 

Those ^M are the Windows newline characters. Or rather ASCII CR. Try searching for just instead of .





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签