我正在学习C标准函数的字符串操作.当我学习这些东西时,我面临着strtok函数和以下代码.
#include <string.h>
#include <stdio.h>
int main()
{
char str[80] = "This is - www.tutorialspoint.com - website";
const char s[2] = "-";
char *token;
/* get the first token */
token = strtok(str, s);
/* walk through other tokens */
while( token != NULL )
{
printf( " %s\n", token );
token = strtok(NULL, s);
}
return(0);
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么在while循环中,strtok与null一起使用?为什么在这里使用null?因为在strtok函数定义中有类似的东西(这个函数使用第二个参数将第一个参数字符串分解为一系列标记.)
当我编译以下代码时,Visual studio显示C4477的警告.为什么这个警告由visual studio产生?我该如何修复此代码?
警告:警告C4477:'printf':格式字符串'%d'需要类型为'int'的参数,但是variadic参数1的类型为'int*'
#include <stdio.h>
int main(void) {
int num = 0;
int *pi = #
printf("Address of num: %d Value: %d\n", &num, num);
printf("Address of pi: %d Value: %d\n", &pi, pi);
return 0x0;
}
Run Code Online (Sandbox Code Playgroud)