这段能在xcode上完美运行的c语言程序在VC上运行不了,这是怎么回事?

2022-08-11 社会 60阅读
//for(int i = LIST_INIT_SIZE-1; i >= N ;i--)//因为C语言不能这样在函数内部声明,只能再函数头部声明,但是C++支持这种,你可以将文件后缀改成.cpp再编译就没问题了
//望采纳
#include 
#include 
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct{
int *elem ;
int length ;
int listsize ;
}SqList ;
void InitList_Sq(SqList *L)
{
L->elem = (int *)malloc(LIST_INIT_SIZE *sizeof(int)) ;
if(!L->elem)
{
exit(-1) ;
}
L->length = 0 ;
L->listsize = LIST_INIT_SIZE ;
printf("InitList Succeed!\n") ;
}
void ListInsert_Sq(SqList *L, int N)
{
printf("Please input the NO.%d element:", N) ;
for(int i = LIST_INIT_SIZE-1; i >= N ;i--)//因为C语言不能这样在函数内部声明,只能再函数头部声明,但是C++支持这种,你可以将文件后缀改成.cpp再编译就没问题了
{
L->elem[i] =L->elem[i-1] ;
}
scanf("%d", &L->elem[N-1]) ;
}
void ListDelete_Sq(SqList * L, int N)
{
printf("The element you want to delete is: %d\n", N) ;
for(int i = 0; i < LIST_INIT_SIZE; i++)
{
if(L->elem[i] == N)
{
for(int j = i; j < LIST_INIT_SIZE-1; j++)
{
L->elem[j] = L->elem[j+1] ;
}
return ;
}
}
}
void LocateElem(SqList *L, int N)
{
int flag = 1 ;
for(int i = 0; i < LIST_INIT_SIZE; i++)
{
if(L->elem[i] == N)
{
printf("The element :%d is at the NO.%d position!\n", N, i+1) ;
flag = 0 ;
}
}
if(flag)
{
printf("The element :%d isn't in this list!\n", N) ;
}
}
void printf_Sq(SqList *L, int N)
{
printf("Now the List is:") ;
for(int i = 0; i{
if(i)
printf(" ") ;
printf("%d", L->elem[i]) ;
}
printf("\n\n") ;
}
int main()
{
SqList *L ;
InitList_Sq(L) ;
int n = 5 ;
for(int i = 1; i <= n; i++)
{
ListInsert_Sq(L, i) ;
}
printf("Insert Finished!\n") ;
printf_Sq(L, n) ;
int del = 6 ;
ListDelete_Sq(L, del) ;
printf_Sq(L, n-1) ;
int pos = 2 ;
ListInsert_Sq(L, pos) ;
printf_Sq(L, n) ;
int judge = 8 ;
LocateElem(L, judge) ;
printf_Sq(L, n) ;
return 0 ;
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com