Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions tests/PA1/mytest1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdio.h>
#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<m;i++)
{
if (i!=4)
{
arr[i] = mymalloc(n*sizeof(int *));
}
}
for (int i=0; i<m; i++)
{
for (int j=0;j<n;j++)
{
if (j != 3)
{
arr[i][j] = mymalloc(o*sizeof(int));
}
}
}
int sum = 0;
for (int i=0; i<m; i++)
{
for (int j=0; j<n ; j++)
{
int * curr = arr[i][j];
for (int k=0;k<o;k++)
{
curr[k] = i+j-o;
}

}
}
return 0;
}
31 changes: 31 additions & 0 deletions tests/PA1/mytest2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
#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;
}
9 changes: 9 additions & 0 deletions tests/PA1/mytest3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <stdio.h>
#include "support.h"

int main(int argc, char const *argv[])
{
FILE * fptr = fopen("fdshg","r");
printf("%d\n",fptr->_flags);
return 0;
}
18 changes: 18 additions & 0 deletions tests/PA1/mytest4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>
#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;
}
12 changes: 12 additions & 0 deletions tests/PA1/mytest5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>
#include "support.h"

int main(int argc, char const *argv[])
{
int * p;
int addr;
scanf("%d",&addr);
p = (int *)addr;
*p = 5;
return 0;
}