c - 在 C 中将字符串解析为 long

标签 c string parsing int

我用 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/

相关文章:

java - java中字符串长度问题

algorithm - 解析带有转义符或定界符的嵌套 block 的最有效算法

javascript - 根据字符标记 JavaScript 字符串

c# - C# 应用程序是否可以与内核驱动程序通信?

c++ - 在Windows下杀死所有未列入白名单的进程

c - 按位循环左移函数

c - 从输入中读取具有定义字符数的字符串

java - Codingbat递归练习(java)

c - 为 Ceasar's Code 在 C 中环绕

java - 运行时的 json 解析错误