#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> typedef struct content{ char* name_block; struct content* after; }blocks; typedef struct status{ int size; int node_id; blocks* block_id; struct status* next; }node; void print_blocks(blocks* block){ blocks* copy = block; while(copy != NULL){ printf("%s ", copy->name_block); copy = copy->after; } } int node_lenght(node* instance){ node* copy = instance; int count = 0; while(copy != NULL){ count++; copy = copy->next; } return count; } void command_ls_all(node* show_list){ if(node_lenght(show_list) == 0){ printf("no more resources available on the computer\n"); } node* copy = show_list; while(copy != NULL){ printf("%d ", copy->node_id); if(copy->block_id != NULL){ printf(": "); } print_blocks(copy->block_id); printf("\n"); copy = copy->next; } } node* nfrn4(node* s, blocks* bid){ node* sim = s; while(sim->block_id->after != NULL) { printf(">>>>>>>\n"); sim->block_id = sim->block_id->after; } sim->block_id->after = bid; return s; } node* nexti(node* nid, blocks* bid){ node* copy = nid; blocks* w = bid; while(copy != NULL){ if(copy->block_id == NULL){ copy->block_id = w; } else copy = nfrn4(copy, w); copy = copy->next; } return nid; } int main(){ node* nid = (node*)malloc(sizeof(node)); nid->node_id = 1; nid->next = (node*)malloc(sizeof(node)); nid->next->node_id = 2; nid->next->next = NULL; blocks* bid = (blocks*)malloc(sizeof(blocks)); bid->name_block = "12"; bid->after = NULL; blocks* bi = (blocks*)malloc(sizeof(blocks)); bi->name_block = "13"; bi->after = NULL; //bi->after->name_block = NULL; // bid->after = (blocks*)malloc(sizeof(blocks)); // bid->after->name_block = "3"; // bid->after->after = (blocks*)malloc(sizeof(blocks)); // bid->after->after->name_block = "23"; // bid->after->after->after = NULL; // nid->block_id = bid; // nid->next->block_id = bid; nid = nexti(nid, bid); // nid = nexti(nid, bi); // printf("%s\n", nid->block_id->name_block); // printf("%s\n", nid->block_id->after->name_block); // printf("%s\n", nid->block_id->after->after->name_block); command_ls_all(nid); print_blocks(bi); print_blocks(bid); return 0; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)