小编Mar*_*k10的帖子

重用 strtok 会给出 null

示例代码:

#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)

c strtok

1
推荐指数
1
解决办法
740
查看次数

在Windows中不同位置初始化变量给出了错误

我在我的代码中初始化简单的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)

c c++ windows compiler-errors visual-studio-2012

0
推荐指数
1
解决办法
53
查看次数

标签 统计

c ×2

c++ ×1

compiler-errors ×1

strtok ×1

visual-studio-2012 ×1

windows ×1