zoukankan      html  css  js  c++  java
  • 一维数组的另一种赋值方法

    #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.

  • 相关阅读:
    hdu 4707 Pet
    hdu 3584 Cube (三维树状数组)
    poj 2155 Matrix (树状数组)
    poj 1195 Mobile phones (树状数组)
    工厂方法模式
    简单工厂模式
    关于设计模式
    UML类图
    UML
    【转载】UML用例图
  • 原文地址:https://www.cnblogs.com/hnrainll/p/2036594.html
Copyright © 2011-2022 走看看