示例代码:
#include <stdio.h>
#include <string.h>
int main()
{
char str[1024];
char *buff, *temp, *result = NULL;
char tok[] = " ";
printf("enter string:\n");
gets(str);
buff = str;
result = strtok(buff, tok);
while (result != NULL)
{
printf("%s\n", result);
result = strtok(NULL, tok);
}
printf("\n");
char tok1[] = " ";
temp = str;
result = strtok(temp, tok1);
while (result != NULL)
{
printf("%s\n", result);
result = strtok(NULL, tok1);
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码给出以下输出:
enter string:
Hello how are you
Hello
how
are
you …Run Code Online (Sandbox Code Playgroud) 我在我的代码中初始化简单的int变量,但它给出了一些不需要的错误...如果我在某些地方使用整数(或其他数据类型)变量,它会给出错误.我写下我的代码并将注释放在整数变量显示错误的位置.
#include<stdio.h>
#include<Windows.h>
//int i; ///********* no problem ************
int main()
{
//int i; ///********* no problem ************
STARTUPINFO si;
PROCESS_INFORMATION pi;
//int i; ///********* no problem ************
ZeroMemory(&si,sizeof(si));
//int i; // error C2143: syntax error : missing ';' before 'type'
si.cb=sizeof(si);
//int i; //error C2143: syntax error : missing ';' before 'type'
ZeroMemory(&pi,sizeof(pi));
//int i; //error C2143: syntax error : missing ';' before 'type'
if(CreateProcess("C:\\Windows\\System32\\notepad.exe",NULL,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi))
{
//int i; ///********* no problem ************
printf("process created\n pid is=%d tid is=%d\n",pi.dwProcessId,pi.dwThreadId);
} …Run Code Online (Sandbox Code Playgroud)