better example - more real usecase
This commit is contained in:
parent
476a01d6d4
commit
bf5ad27064
32
array_handle_test.c
Normal file
32
array_handle_test.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "handle.h"
|
||||
|
||||
struct Vektor {
|
||||
int count;
|
||||
int *v;
|
||||
}; handle(Vektor) {
|
||||
if(state == HANDLE_CREAT) {
|
||||
this->count = *(int*) data;
|
||||
this->v = calloc(this->count, sizeof(int));
|
||||
} else if (state == HANDLE_DESTR){
|
||||
if(this->v) free(this->v);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
printf("Number of elements to sum: ");
|
||||
scanf(" %d", &n);
|
||||
creat(Vektor, data, &n);
|
||||
// printf("vektor.count:%d\n", data.count);
|
||||
|
||||
for(int i = 0; i < data.count; ++i) {
|
||||
scanf(" %d", &n);
|
||||
data.v[i] = n;
|
||||
}
|
||||
n = 0; for(int i = 0; i < data.count; ++i) n += data.v[i];
|
||||
printf("Sum: %d\n", n);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user