无法解析变量'scanf_s'?

时间:2017-11-22 01:39:32

标签: c clion

我目前正在使用新的15英寸HP Spectre 360​​x笔记本电脑,它运行最新的Windows 10 Home,而我正在使用CLion 2017.2.3作为我的简单C程序的IDE,这是一个编译问题.Cake的版本是3.10.0;但我似乎无法解决这个编译问题; CMake突出显示。有人可以请我解决这个问题吗?

    // Program 7.11 A dynamic prime example
    #define _STDC_WANT_LIB_EXT1_ 1
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdbool.h>

    int main(void)
    {
        unsigned long long *pPrimes = NULL;   // Pointer to primes storage area
        unsigned long long trial = 0;         // Integer to the tested
        bool found = false;                   // Indicates when we find a prime
        int total = 0;                        // Number of primes required
        int count = 0;                        // Number of primes found

    printf("How many primes would you like - you'll gert at least 4?  ");
    scanf_s("%d", &total);                // Total is how many we need to find
    total = total < 4 ? 4 : total;        // Make sure it is at least 4

    // Allocate sufficient memory to store the number of primes required
    pPrimes = (unsigned long long*) malloc(total* sizeof(unsigned long long));
    if(!pPrimes)
    {
        printf("Not enough memory. It's the end I'm afraid.\n");
        return 1;
    }

    // We know the first three primes so let's give the program a start
    *pPrimes = 2ULL;
    *(pPrimes + 1) = 3ULL;
    *(pPrimes + 2) = 5ULL;
    count = 3;
    trial = 5ULL;

    // Find all the primes required
    while(count < total)
    {
        trial +- 2ULL;                    // next value for checking

        // Divide by the primes we have. If any divide exactly - it's not prime
        for(int i = 1 ; i < count ; ++i)
        {
            if(!(found = (trial % *(pPrimes + i))))
                break;                      // Exit if zero remainder
        }

        if(found)                           // We got one - if found is true
            *(pPrimes + count++) = trial;   // Store it and increment count
    }
    // Display primes 5-up
    for(int i = 0 ; i < total ; ++i)
    {
        printf("%12llu", *(pPrimes + i));
        if(!((i+1) % 5))
            printf("\n");
    }
    printf("\n");

    free(pPrimes);
    pPrimes = NULL;
    return 0;
}

CMakeLists.text文件是......

cmake_minimum_required(VERSION 3.10)
project(untitled1)

set(CMAKE_C_STANDARD 11)

set(SOURCE_FILES main.c)
add_executable(untitled1 ${SOURCE_FILES})

0 个答案:

没有答案