一维数组的另一种赋值方法

#include <stdio.h>
#include
<stdlib.h>
#include
<windows.h>
char head[]="HTTP/1.1 200 OK\r\n" \
"Content-Type: text/html\r\n"\
"\r\n";

int main()
{
int i,j;
i
= sizeof(head);
printf(
"sizeof(head) = %d\n",i);
printf(
"strlen(head) = %d\n",strlen(head));
for(j = 0; j< i; j++)
{

printf(
"%c",head[j]);
fflush(stdout);
Sleep(
1000);
}

return 0;
}

现象说明:

说明:

本程序主要为了说明两个问题:

1.一维数组的一种赋值方式:

char head[]="HTTP/1.1 200 OK\r\n" \

      "Content-Type: text/html\r\n"\

      "\r\n";

2.strlen和sizeof计算数组大小时的区别

最重要的一点:strlen()不会计算'\0'.在写web服务器时,对浏览器发数据时,要用strlen.

在本题中,sizeof和strlen的计算相差1.

posted @ 2011-05-04 15:53  hnrainll  阅读(821)  评论(0编辑  收藏  举报