我需要能够输入int
s 数组并将其保存在 a 内的集合中struct
,但是由于某种原因,它不会将数字读入数组:
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#define MAX 100
typedef struct set {
int arr[MAX];
} set;
set SETA;
int read_set(set,...);
void print_set(set);
int main(){
int x;
x=read_set(SETA,2,3,4,-1);
printf("%d numbers were read\n",x);
print_set(SETA);
return 0;
}
void print_set(set s){
int *iptr;
iptr=s.arr;
while(*iptr++){
printf("%d ",*iptr);
}
}
int read_set(set s,...){
va_list ap;
int i=0;
int c=0;
va_start(ap,s);
while( *ap != -1){
s.arr[i++]=va_arg(ap,int);
printf("%d was entered\n",s.arr[i]);
c++;
}
va_end(ap);
return c;
}
我得到的输出是:
0 was entered
0 was entered
0 was entered
3 numbers were read
不用说 print_set 什么也不打印。