「已注销」
2015-05-14 05:03
采纳率: 100%
浏览 1.7k
已采纳

VS2013使用scanf_s过界

无法运行,代码如

// info.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <string.h>
//infomation
//technology
//IT
//冒泡 选择 插入排序
//快速排序 归并排序
struct SInfo
{
    char sName[20];
    char sTele[20];
};


int _tmain(int argc, _TCHAR* argv[])
{
    SInfo inf[5];
#define COUNT sizeof(inf)/sizeof(inf[0])
    int i = 0;
    while (i < COUNT)
    {
        printf("请输入第%d个学生姓名和电话:【以空格间隔】", i + 1);
        fflush(stdin);
        scanf_s("%s %s", inf[i].sName, inf[i].sTele);       //调试到这错误
        ++i;
    }
    //ccc aaa ddd bbb eee
    i = 0;
    unsigned int j = 0;
    while (i < COUNT - i)
    {
        j = 0;
        while (j < COUNT - i)
        {
            if (strcmp(inf[j].sName, inf[j + 1].sName) > 0)
            {
                SInfo t = inf[j];
                inf[j] = inf[j + 1];
                inf[j + 1] = t;
            }
            ++j;
        }
        ++i;
    }
    i = 0;
    while (i < COUNT)
    {
        printf("%s\t%s\n", inf[i].sName, inf[i].sTele);
        ++i;
    }
    return 0;
}

调试之后出现
Unhandled exception at 0xFEFEFEFE in info.exe: 0xC0000005: Access violation executing location 0xFEFEFEFE.
麻烦大神讲解下,谢谢

1条回答 默认 最新

相关推荐 更多相似问题