From 0f9a9d65921fc67e7bf720bf12a4349f70a35ef4 Mon Sep 17 00:00:00 2001 From: kdh422 <superb422@naver.com> Date: Sat, 16 Jun 2018 19:19:26 +0900 Subject: [PATCH] only make malloc --- main.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index b5fba06..c773419 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,51 @@ #include "alloc.h" +#include <stdio.h> +#include <string.h> +#include <stdlib.h> -int main() +int main(int argc, char *argv[]) { + int tok,tmp,idx=0; + FILE * f; + char r_size[1000]; + + + if((f=fopen(argv[1],"r"))==NULL) + { + printf("File open error.\n"); + return -1; + } + fgets(r_size,sizeof(r_size),f); + + char *ptr=strtok(r_size," "); + tok=atoi(ptr); + char **command=(char**)malloc(sizeof(char*)*tok); + ptr=strtok(NULL," "); + + for(int i=0;i<tok; i++) + { + memset(r_size,'\0',sizeof(r_size)); // idx + fgets(r_size,sizeof(r_size),f); // get read + r_size[strlen(r_size)-1]='\0'; // End of string is null + + if(r_size[0]=='s'){ + command[idx] = make_malloc(strlen(r_size+1)); + strcpy(command[idx++],r_size+1); + } + } + + read_start=start; + + while(read_start){ + + printf("free : %d / size : %d ", read_start->free,read_start->size); + + if(!read_start->free) + printf("%s\n",read_start->offset); + + read_start=read_start->next; + + } + return 0; } -- GitLab