Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的程序中,我将用户名作为启动参数并从服务器获取用户 ID。服务器和客户端已连接!但我需要将用户名和用户 ID(属于用户名)放在一起,将它们发送回服务器,最后根据用户 ID 对它们进行排序。有什么建议么?
只需将它们都发送到服务器,注意包含某种分隔符,以便解析流并识别哪个部分是哪个部分。
例如,您可以使用 NIL 字节将两者分开,在用户 ID 之后也可以使用最终的 NIL。这假设两者都是字符串。
在服务器上,只需将传入的数据存储到结构数组中,并qsort()在收集到所有数据后对数组进行排序。
qsort()