diff --git a/tests/PA1/mytest1.c b/tests/PA1/mytest1.c new file mode 100644 index 000000000..4d37fb435 --- /dev/null +++ b/tests/PA1/mytest1.c @@ -0,0 +1,41 @@ +#include +#include "support.h" + +int main(int argc, char const *argv[]) +{ + int n = 10; + int m = 5; + int o = 6; + int *** arr = mymalloc(m*sizeof(int **)); + for (int i=0;i +#include "support.h" + +struct node +{ + int val; + struct node * next; +}; + +int main(int argc, char const *argv[]) +{ + struct node * head = (struct node * ) mymalloc(sizeof(struct node)); + struct node * curr = head; + for (int i=0 ; i<10; i++) + { + curr->val = i+5; + curr->next = (struct node * )mymalloc(sizeof(struct node)); + curr = curr->next; + } + curr = head; + int i = 5; + int sum = 0; + while (i>0) + { + sum += curr->val; + curr = curr->next; + i--; + } + printf("%d\n",sum); + return 0; +} diff --git a/tests/PA1/mytest3.c b/tests/PA1/mytest3.c new file mode 100644 index 000000000..a5720ef11 --- /dev/null +++ b/tests/PA1/mytest3.c @@ -0,0 +1,9 @@ +#include +#include "support.h" + +int main(int argc, char const *argv[]) +{ + FILE * fptr = fopen("fdshg","r"); + printf("%d\n",fptr->_flags); + return 0; +} diff --git a/tests/PA1/mytest4.c b/tests/PA1/mytest4.c new file mode 100644 index 000000000..d070e3b8a --- /dev/null +++ b/tests/PA1/mytest4.c @@ -0,0 +1,18 @@ +#include +#include "support.h" + +int main(int argc, char const *argv[]) +{ + int input; + scanf("%d",&input); + int * ptr; + if (input>0) + { + ptr = mymalloc(4); + }else + { + ptr = NULL; + } + *ptr = 6; + return 0; +} diff --git a/tests/PA1/mytest5.c b/tests/PA1/mytest5.c new file mode 100644 index 000000000..781e4b05b --- /dev/null +++ b/tests/PA1/mytest5.c @@ -0,0 +1,12 @@ +#include +#include "support.h" + +int main(int argc, char const *argv[]) +{ + int * p; + int addr; + scanf("%d",&addr); + p = (int *)addr; + *p = 5; + return 0; +}