打印动态数组,VisualStudio-c

打印动态数组,VisualStudio-c,c,arrays,dynamic,C,Arrays,Dynamic,我用C写了一个简单的代码来练习动态数组,但是VisualStudio不能正常运行吗?它没有显示错误,似乎存储了输入,但不打印。请帮忙 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #define SIZE 3 int main(void){ int *a = malloc(SIZE * sizeof(int)); int i; if (a == N

我用C写了一个简单的代码来练习动态数组,但是VisualStudio不能正常运行吗?它没有显示错误,似乎存储了输入,但不打印。请帮忙

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define SIZE 3

int main(void){

    int *a = malloc(SIZE * sizeof(int));
    int i;

    if (a == NULL){
        puts("not enough memory");
    }
    else{
        for (i = 0; i < SIZE; i++){
            printf("entry %d\n", i+1);
            scanf("%d", &a[i]);
        }
        printf("printing\n");
        for (i = 0; i < SIZE; i++){
            printf("%d\n", a[i]);
        }
            free(a);

        puts("press any key to exit...");
        getchar();
        return 0;
    }
}
\define\u CRT\u SECURE\u NO\u警告
#包括
#包括
#定义尺寸3
内部主(空){
int*a=malloc(SIZE*sizeof(int));
int i;
如果(a==NULL){
放置(“内存不足”);
}
否则{
对于(i=0;i
scanf中未使用的换行符(最后)在最后一次getchar中使用。它不会像你想的那样变成停止状态

举个例子如下

改变

scanf("%d", &a[i]);
getchar();

改变

scanf("%d", &a[i]);
getchar();


您的代码看起来很好,可以为我运行,包括在末尾打印输入的值。你确定这是正确的代码吗?如果是,您使用的是哪个版本的Visual Studio,以及如何编译它?工作正常…没问题!我正在使用VS 2013 pro。我使用本地windows调试器。输入最后一个值后,程序关闭。