在复习C语言的时候写了很简单的一个结构,代码如下:
#include
#include
struct student
{
char name[20];
int chinese;
int math;
double average;
};
void main()
{
student st[3];
int i,n;
printf("请输入学生个数\n");
scanf_s("%d", &n);
printf("请输入学生的姓名 语文成绩 数学成绩\n");
for (i = 0; i < n; i++)
{
scanf_s("%s %d %d", st[i].name, &st[i].chinese, &st[i].math);
st[i].average = (st[i].chinese + st[i].math ) / 2.0;
}
for (i = 0; i < n; i++)
printf("%s 平均成绩为:%f\n", st[i].name, st[i].average);
system("pause");
}
求问各位大佬调试的时候为什么会报错 “0x008C0B5C (ucrtbased.dll)处(位于 ConsoleApplication1.exe 中)引发的异常: 0xC0000005: 写入位置 0x3C900000 时发生访问冲突。”
//将输入部分修改一下:
for (i = 0; i < n; i++)
{
scanf_s("%s", st[i].name, 20);
scanf_s("%d %d", &st[i].chinese, &st[i].math);
st[i].average = (st[i].chinese + st[i].math) / 2.0;
}
//scanf_s在读入字符串的时候要加入size大小
scanf("%s %d %d",st[i].name, &st[i].chinese, &st[i].math);
#include <stdio.h>
void main( void )
{
int i, result;
float fp;
char c, s[81];
wchar_t wc, ws[81];
printf( "\n\nEnter an int, a float, two chars and two strings\n");
result = scanf( "%d %f %c %C %s %S", &i, &fp, &c, &wc, s, ws );
printf( "\nThe number of fields input is %d\n", result );
printf( "The contents are: %d %f %c %C %s %S\n", i, fp, c, wc, s, ws);
wprintf( L"\n\nEnter an int, a float, two chars and two strings\n");
result = wscanf( L"%d %f %hc %lc %S %ls", &i, &fp, &c, &wc, s, ws );
wprintf( L"\nThe number of fields input is %d\n", result );
wprintf( L"The contents are: %d %f %C %c %hs %s\n", i, fp, c, wc, s, ws);
}
#include <stdio.h>
int main( void )
{
int i,
result;
float fp;
char c,
s[81];
wchar_t wc,
ws[81];
result = scanf_s( "%d %f %c %C %s %S", &i, &fp, &c, 1,
&wc, 1, s, 80, ws, 80 );
printf( "The number of fields input is %d\n", result );
printf( "The contents are: %d %f %c %C %s %S\n", i, fp, c,
wc, s, ws);
result = wscanf_s( L"%d %f %hc %lc %S %ls", &i, &fp, &c, 2,
&wc, 1, s, 80, ws, 80 );
wprintf( L"The number of fields input is %d\n", result );
wprintf( L"The contents are: %d %f %C %c %hs %s\n", i, fp,
c, wc, s, ws);
}
canf_s("%s %d %d", st[i].name, &st[i].chinese, &st[i].math);
st[i].name前没有加取地址符号