Bzero:Prototype: void bzero (void * s, int N );Function: set the first n Bytes of the byte string s to zero and include '\ 0 '.Note: bzero has no return value, and strings is used. h header file, strings. h was once part of the POSIX standard, but in the POSIX.1-2001 standard, these functions are marked as legacy functions and are not recommended.These functions are no longer in the POSIX.1-2008 standard. W
////////////////////////////////////
// Server code
///////////////////////////////////
// This file is the server code
# Include
# Include For socket
# Include # Include
# Include Exit
# Include # Include
# DefineHello_world_server_port 7754# Define length_of_listen_queue 20# DefineBuffer_size 1024
Int main (INT argc, char ** argv){// Set a socket address structure server_addr, which represents the Internet address and port of the server.Struct sockaddr_inServer_addr;
compile under VC6.0 and MinGW5; it is said that the GCC support under Linux, but the author did not close test. In view of this, use memcpy () instead.
For more information, see the differences between the C language bcopy () and memcpy (), bzero () and memset (), bcmp () and memcmp () functions
The author defines a macro that is compiled and passed under VC6.0, with the following code:
#include
Execution results:
Bcopy (): St
service request, a new socket is generated. The SERver displays the IP address of the client and sends the string "hi, I am SERver!" to the client through the new socket! ". Close the socket.
Main (){Int sock_fd, client_fd;/* sock_fd: * socket; client_fd: Data Transmission socket */Struct sockaddr_in ser_addr;/* local address information */Struct sockaddr_in cli_addr;/* client address information */Char msg [MAX_MSG_SIZE];/* buffer */Ser_sockfd =Socket(AF_INET, SOCK_STREAM, 0);/* Create the con
displays the IP address of the client and sends the string "Hi,i am server!" to the client through a new socket. Finally, close the socket.
Main (){int sock_fd,client_fd; /*SOCK_FD: Monitor SOCKET;CLIENT_FD: Data transfer Socket */struct sockaddr_in ser_addr; /* Native Address information */struct sockaddr_in cli_addr; /* Client Address information */Char msg[max_msg_size];/* buffer */Ser_sockfd=socket (af_inet,sock_stream,0);/* Create a connected socket */if (ser_sockfd{/* Create
HTTP header.
Configuration File (config.txt ):
PORT = 8000Directory =./peizhi
HTML file (index_html ):
First name:
Last name:
Server code:
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Define MAXLINE 80
Void deal_config (int * port_number, char * path );
Int ma
The implementation of the server and the client chat with each other, no order restrictions, can be carried out at the same time.
Service side: SERVER.C
#include #include #include #include #include #include #include #include #include #include
#define MAXBUF 1024int main (int argc, char *argv[]){int pid;int SOCKFD, NEW_FD;Socklen_t Len;struct sockaddr_in my_addr, their_addr;unsigned int myport, lisnum;Char buf[maxbuf + 1];if (argv[2])MyPort = Atoi (argv[2]); /* Converts command line string to In
the same length as the struct sockaddr, which can be set to zero with the bzero () or memset () function. Pointers to sockaddr_in and pointers to SOCKADDR can be converted to each other, which means that if a function requires a type of argument that is sockaddr, you can convert a pointer to a sockaddr_in to a pointer to a sockaddr when the function calls. , or vice versa.When using the BIND function, you can use the following assignment to automatic
and analysis of the test results are given in this paper.
3. Example
The source code used for the first test is simple, as follows:
1 int
2 main (int argc, char *argv[])
3 {
4 int i, n;
5
6 n = atoi (argv[1]);
7 Char arr[n+1];
8 Bzero (arr, (n+1) * sizeof (char));
9 for (i = 0; i arr = (char) (' A ' + i);
11}
Arr[n] = '/0 ';
printf ("%s/n", arr);
14
return (0);
16}
The above program is named Dynarray.c, whose job is to add the value of the parameter
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.