無法運行,代碼如
// 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.
麻煩大神講解下,謝謝
scanf_s需要指定每個輸入字符串長度
scanf_s("%s %s", inf[i].sName,8 ,inf[i].sTele,11);