fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. typedef struct char_node *char_list;
  6.  
  7. struct char_node{
  8. char info;
  9. char_list next;
  10. }char_node;
  11.  
  12. char_list makesNode(void);
  13. char_list makesValueNode(char value);
  14. char_list makesList(char nome[]);
  15. void viewNode(char_list l);
  16. void viewList(char_list l);
  17.  
  18. int main(){
  19. char nome[] = "Ugo";
  20. char_list nuovo = makesList(nome);
  21. if(nuovo != NULL)
  22. viewList(nuovo);
  23. return 0;
  24. }
  25.  
  26. char_list makesNode(void){
  27. return (char_list)malloc(sizeof(struct char_node));
  28. }
  29.  
  30. char_list makesValueNode(char value){
  31. char_list li = NULL;
  32. li = makesNode();
  33. li -> info = value;
  34. li -> next = NULL;
  35. return li;
  36. }
  37.  
  38. char_list makesList(char nome[]){
  39. char_list nuovo;
  40. char_list head = NULL;
  41. int l = strlen(nome);
  42. l = l - 1;
  43. while(l >= 0 ){
  44. nuovo = makesValueNode(nome[l]);
  45. if(nuovo != NULL){
  46. nuovo -> next = head;
  47. head = nuovo;
  48. l = l - 1;
  49. }
  50. }
  51. return nuovo;
  52. }
  53.  
  54. void viewNode(char_list l){
  55. printf("%c", l->info);
  56. }
  57.  
  58. void viewList(char_list l){
  59. while(l != NULL){
  60. viewNode(l);
  61. l = l -> next;
  62. }
  63. }
  64.  
Success #stdin #stdout 0s 4400KB
stdin
Standard input is empty
stdout
Ugo