#include <stdio.h> #include <stdlib.h> struct node { int id; char *name; struct node *next; }; void display(struct node *n); int main(int argc,char** argv) { struct node *root, *next; next = malloc(sizeof(struct node*)); root = next; root->id = 1; root->name = argv[0]; for(int i = 1; i < argc; i++) { next = next->next = malloc(sizeof(struct node*)); next->id = i + 1; next->name = argv[i]; } next->next = NULL; display(root); return 0; } void display(struct node *n) { do { printf("[%d] = %s\r\n", n->id, n->name); } while( n = n->next ); }
t.me/perfect0sight
для компиляции можно использовать https://bellard.org/tcc/ следующим образом:
ОтветитьУдалитьtcc main.c
тестовый запуск:
C:\tcc\examples>main.exe 1 2 3 [1] = C:\tcc\examples\main.exe [2] = 1 [3] = 2 [4] = 3
(*linked list example for freepascal *)
ОтветитьУдалитьprogram LinkedList;
type
point2node = ^node;
node = record
i: integer;
Next: point2node;
end;
var
root, tmp: point2node;
begin
(* init list *)
new(tmp);
Read(tmp^.i);
root := tmp;
(* read elements from std input *)
while not EOF() do
begin
new(tmp^.Next);
Read(tmp^.Next^.i);
tmp := tmp^.Next;
end;
(* finalize list *)
tmp^.Next := nil;
(* output from head to tail *)
while root <> nil do
begin
writeln('i = ', root^.i);
root := root^.Next;
end;
end.