I have error

Hi,
I have an error.

1
2
3
4
5
6
7
8
9
10
11
12
  #include "stdafx.h"




int _tmain(int argc, _TCHAR* argv[])
{
    char str1[10], str2[10];
    printf("Enter a str : ");
    scanf_s("%s%s", str1, str2);
    printf("You entered %s and %s\n", str1, str2);
}
Copy and paste the exact error message you see. Make sure it is the first error.
If I had to guess what the error is, it would be that your format string for scanf_s is wrong.
I think that in the 10th line
scanf_s("%s%s", str1, str2);
you need to write it:
1
2
3
4
scanf_s("%s",str1);
fflush(stdin);   //you need to flush the input file.
scanf_s("%s",str2);
fflush(stdin);
From MSDN:
Unlike scanf and wscanf, scanf_s and wscanf_s require the buffer size to be specified for 
all input parameters of type c, C, s, S, or string control sets that are enclosed in []. 
The buffer size in characters is passed as an additional parameter immediately following 
the pointer to the buffer or variable. For example, if you are reading a string, the 
buffer size for that string is passed as follows: 

char s[10]; 

scanf_s("%9s", s, _countof(s)); // buffer size is 10, width specification is 9 

http://msdn.microsoft.com/en-us/library/w40768et.aspx
Topic archived. No new replies allowed.