简体   繁体   中英

c++ tolower a char array in a server and client program?

I am sending the server a message. For example: "Hello World." I want the server to send back the message: "hello world."

for(;;) //listen forever
{
    ClntLen = sizeof(ClntAddr);
    NewSockfd = Accept(Sockfd, (sockaddr*)&ClntAddr, &ClntLen);

    //Read message
    read(NewSockfd, Buff, MAX_SIZE);
    //convert to lower, send back to client
    write(NewSockfd, Buff, MAX_SIZE);
    close(NewSockfd);
}

I have tried using tolower(), but in a server I just can't get it right without giving me errors.

Summary: Read Buff (char array), convert it to lowercase, Write it back to the client.

Please explain how its done. Thanks in advance.

Show us your code to call tolower, please

When you call read, you should get its return value as the actual data returned from socket and then call tolower to convert them to lowercase and then send this buffer back with the length it returned from read.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM