简体   繁体   中英

A question about scanf_s and pointer array

occer an error in scanf_s. I wrote #define _CRT_SECURE_NO_WARNINGS instead of scanf_s , but it doesn't work. In my opinion, scanf_s does not receive two arguments.

#include <stdio.h>

#define SIZE 80

void mystery1(char* s1, const char* s2);

int main(void)
{
    char string1[SIZE];
    char string2[SIZE];

    puts("Enter two strings: ");
    scanf_s("%79s%79s", string1, string2);  // Error
    mystery1(string1, string2);
    printf("%s", string1);
}

void mystery1(char* s1, const char* s2)
{
    
    while (*s1 !='\0')
    {
        ++s1;
    }
    for (; *s1 = *s2; ++s1, ++s2)
    {
        ;
    }
}

Input

helloworld

The arguments you are using is scanf function scanf("%79s%79s", string1, string2); . The scanf_s function is used like this:

scanf_s("%79s%79s", string1, 80, string2, 80)

I don't know what this function void mystery1(char* s1, const char* s2) does? but in the for loop you have to use "==" instead of "="

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM