Skip to content
Snippets Groups Projects
Commit de2d860c authored by Hywon woong Jang's avatar Hywon woong Jang
Browse files

Ver3.1 complete file I/O

parent 6d1309f5
Branches
No related tags found
No related merge requests found
#include "alloc.h" #include "alloc.h"
#include "stdlib.h"
int main(int argc, char ** argv)
int main()
{ {
int num; int num;
char * str[100]; char * str[100];
char move[4096]; // enough size; char buf[1024]; // enough size;
meta * temp = NULL; meta * temp = NULL;
char * save = NULL; char * save = NULL;
char flag; char flag;
...@@ -13,43 +13,61 @@ int main() ...@@ -13,43 +13,61 @@ int main()
int sequence; int sequence;
int n = 0; int n = 0;
int i= 0; int i= 0;
scanf("%d %c",&num, &Algorithm); FILE *fp = fopen(argv[1], "r");
if(fp == NULL)
{
printf("Invalid File name.. please recheck File name\n");
return 0;
}
fgets(buf, sizeof(buf), fp);
save = strtok(buf , " ");
flag = atoi(save);
save = strtok(buf , " ");
if(strcmp(save , "W") == 0)
Algorithm = 'W';
else if(strcmp(save , "B") == 0)
Algorithm = 'B';
for(i=0; i < num; i++) else if(strcmp(save , "F") == 0)
Algorithm = 'F';
while(i++ < flag)
{ {
// printf("here?\n"); fgets(buf, sizeof(buf), fp);
scanf(" %c",&flag); save = strtok(buf , " ");
if(flag == 'r')
if(strcmp(save , "r") == 0)
{ {
scanf(" %d %d",&sequence , &size); save = strtok(NULL , " ");
sequence = atoi(save);
save = strtok(NULL , " ");
size = atoi(save);
temp = choose_meta(sequence); temp = choose_meta(sequence);
temp = m_realloc(temp + 1 , size); temp = m_realloc(temp + 1 , size);
} }
else if(flag == 's') else if(strcmp(save , "s") == 0)
{ {
// printf("asdf\n"); save = strtok(NULL , "\n");
scanf(" %[^\n]",move); str[n] = m_malloc(strlen(save) +1);
// printf("size : %d\n", strlen(move)); // printf("buf = %s\n",save);
str[n] = m_malloc(strlen(move) +1); strcpy(str[n++], save);
strcpy(str[n++], move);
// printf("strlen : %d\n" ,strlen(str[n -1]));
} }
else if(flag == 'f') else if(strcmp(save , "f") == 0)
{ {
scanf(" %d",&sequence); save = strtok(NULL , " ");
// printf("sequence = %d \n",sequence); sequence = atoi(save);
temp = choose_meta(sequence); temp = choose_meta(sequence);
m_free(temp + 1); m_free(temp + 1);
} }
else if(flag == 'e') else if(strcmp(save , "e") == 0)
{ {
scanf(" %d",&size); save = strtok(NULL , " ");
size = atoi(save);
m_malloc(size); m_malloc(size);
} }
} }
temp = META.Head; temp = META.Head;
i=0; i=0;
printf("\n"); // printf("\n");
while(temp != NULL) while(temp != NULL)
{ {
save = temp + 1; save = temp + 1;
...@@ -61,6 +79,7 @@ int main() ...@@ -61,6 +79,7 @@ int main()
temp = temp ->next; temp = temp ->next;
} }
fclose(fp);
// printf("\n"); // printf("\n");
// print_link(); // print_link();
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment