"您可以使用strchr函数来找到字符串中的冒号,并将冒号后面的内容赋给temp。以下是一个示例代码:\n\nc\n#include <stdio.h>\n#include <string.h>\n\nint main() {\n unsigned char *rxbuf = \"wdy:32\" ;\n unsigned int temp; \n\n char *colon = strchr(rxbuf, ':');\n if (colon != NULL) {\n temp = atoi(colon + 1);\n printf(\"temp: %u\n\", temp);\n } else {\n printf(\"Colon not found\n\");\n }\n \n return 0;\n}\n\n\n在上述代码中,strchr函数用于查找字符串中第一次出现的冒号的位置,并返回一个指向该位置的指针。然后,atoi函数用于将冒号后面的字符串转换为整数。最后,将得到的整数赋给temp并打印出来。\n\n请注意,上述代码假设冒号后面的内容是一个以数字开头的字符串,并且不包含其他非数字字符。如果冒号后面的内容可能包含其他非数字字符,您可能需要使用其他方法来提取数字部分。\n

C语言提取字符串中冒号后面的数字

原文地址: https://www.cveoy.top/t/topic/qinP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录