fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define BUFFER 65
  6. #define PROC_STR(pstr) if((pstr[strlen((pstr)) - 1]) == '\n') (pstr[strlen((pstr)) - 1]) = '\0'
  7. #define PROC_STR1(pstr) strcspn(pstr, "\n") = 0
  8.  
  9. typedef struct blck{
  10. char string[BUFFER];
  11.  
  12. struct blck *prev;
  13. struct blck *next;
  14. }Block;
  15.  
  16. typedef struct blkch{
  17. long unsigned int len;
  18.  
  19. Block *gen;
  20. Block *tail;
  21. }BlockChain;
  22.  
  23. /* Create the list */
  24. BlockChain *createBlockChain(){
  25. BlockChain *newChain = calloc(1, sizeof(BlockChain));
  26.  
  27. newChain->gen = NULL;
  28. newChain->tail = NULL;
  29. newChain->len = 0;
  30.  
  31. return newChain;
  32. }
  33.  
  34. /* Create a node */
  35. Block *createBlock(char *pstring){
  36. Block *newBlock = calloc(1, sizeof(Block));
  37.  
  38. strcpy(newBlock->string, pstring);
  39.  
  40. return newBlock;
  41. }
  42.  
  43. /* Append Block to the list*/
  44. BlockChain *appendToChain(BlockChain *pChain, char *pstring){
  45. Block *newBlock = createBlock(pstring);
  46.  
  47. newBlock->prev = pChain->tail;
  48. newBlock->next = NULL;
  49. if(pChain->tail != NULL)
  50. pChain->tail->next = newBlock;
  51. pChain->tail = newBlock;
  52. if(pChain->gen == NULL)
  53. pChain->gen = newBlock;
  54. pChain->len++;
  55.  
  56. return pChain;
  57. }
  58.  
  59. void printBlock(Block *pblock){
  60. printf("String: %s\n", pblock->string);
  61. printf("Prev: %p\n", (void *) pblock->prev);
  62. printf("Cur: %p\n", (void *) pblock);
  63. printf("Next: %p\n", (void *) pblock->next);
  64. }
  65.  
  66. void printChain(Block *pgen){
  67. Block *tmp = pgen;
  68.  
  69. while(tmp != NULL){
  70. printBlock(tmp);
  71. tmp = tmp->next;
  72. }
  73. }
  74.  
  75. int main(void){
  76. BlockChain *myChain = createBlockChain();
  77.  
  78. appendToChain(myChain, "Hello1");
  79. appendToChain(myChain, "Hello2");
  80. printChain(myChain->gen);
  81. free(myChain);
  82. return 0;
  83. }
Compilation error #stdin compilation error #stdout 0s 4392KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty