我用 python 编写了服务器,用 C 编写了客户端。
python 服务器向 C 客户端发送“1 1000\n”。
接收此字符串的 C 函数应将其解析为两个 long int。
void receive_job() {
char tmp_buffer[256];
long start, stop;
recv(sock, tmp_buffer, 255, 0);
/*
here I wonder how I can parse tmp_buffer to set start and stop values.
*/
}
我不是很精通 C,所以我很感激对此的评论。
最佳答案
查看 strtol() 或 strtoul(),具体取决于您的具体数据类型:
char end;
long x = strtol(tmp_buffer,&end,10);
long y = strtol(end+1,NULL,10);
关于c - 在 C 中将字符串解析为 long,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7930167/