- 论坛徽章:
- 0
|
请问sizeof 与strlen的区别?
大家帮我看看,下面的两段程序得出的 a,aa,my_temp_web的结果不同,请问这是为什么?谢谢!
- #include "string.h"
- #define u_char unsigned char
- u_char code MY_WEB[] = {
- "<html>;\r\n"
- "</html>;\r\n"
- };
- const unsigned char REPLY_GET[] = // 1st thing our server sends to a client
- {
- "HTTP/1.0\r\n" // protocol ver 1.0, code 200, reason OK
- "\r\n" // indicate end of HTTP-header
- };
- void main(void)
- {
- u_char my_temp_web[150];
- u_char i;
- u_char a,aa;
-
- a = strlen(MY_WEB) + strlen(REPLY_GET);
- memcpy(my_temp_web,REPLY_GET,strlen(REPLY_GET));
- memcpy(&my_temp_web[strlen(REPLY_GET)],MY_WEB,strlen(MY_WEB));
- aa = strlen(my_temp_web);
- while(1){i = 1;}
-
- }
复制代码
- #include "string.h"
- #define u_char unsigned char
- u_char code MY_WEB[] = {
- "<html>;\r\n"
- "</html>;\r\n"
- };
- const unsigned char REPLY_GET[] = // 1st thing our server sends to a client
- {
- "HTTP/1.0\r\n" // protocol ver 1.0, code 200, reason OK
- "\r\n" // indicate end of HTTP-header
- };
- void main(void)
- {
- u_char my_temp_web[150];
- u_char i;
- u_char a,aa;
-
- a = sizeof(MY_WEB) + sizeof(REPLY_GET);
- memcpy(my_temp_web,REPLY_GET,sizeof(REPLY_GET));
- memcpy(&my_temp_web[sizeof(REPLY_GET)],MY_WEB,sizeof(MY_WEB));
- aa = sizeof(my_temp_web);
- while(1){i = 1;}
-
- }
复制代码 |
|