-3
동적 메모리 할당을 사용하여이 간단한 버블 정렬 프로그램을 작성했습니다. 저는 VC++ 컴파일러를 사용하고 있습니다.이 프로그램에서 잘못된 점은 무엇입니까?
// bubble_sort.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
void bubble_sort(int a[],int n);
int main()
{
int *p,i;
int n;
printf("Enter number of array elements\n");
scanf("%d",&n);
p=(int*)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
scanf("%d",(p+i));
bubble_sort(p,5);
printf("Sorted elements\n");
for(i=0;i<n;i++)
printf("%d ",p[i]);
free(p);
system("pause");
return 0;
}
void bubble_sort(int a[],int n)
{
int i,j,temp;
for(i=0;i<n;i++)
{
for(j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
위의 프로그램에서 잘못된 점은 무엇입니까? 컴파일러는 다음 경고를 표시합니다. 무슨 뜻이에요?
Warning 1 warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
Warning 2 warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
도와주세요.
경고는 당신이 거의 알아야 할 모든 것을 말해줍니다. 어느 부분이 불분명합니까? – Biffen
그런 질문은 아마도 http://codereview.stackexchange.com/에 더 적합 할 것입니다. 그러나 프로그램이 예상 한대로 작동한다면 그것은 올바른 의미입니다. – Biffen
scanf에는 많은 문제가 있으므로 피해야합니다. - http://c-faq.com/stdio/scanfprobs.html – user93353