Home > Back-end >  A question about scanf_s and pointer array
A question about scanf_s and pointer array

Time:12-07

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("ysys", 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

CodePudding user response:

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

scanf_s("ysys", 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 "="

  •  Tags:  
  • c
  • Related