list to string python

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node* next;
};

char list_to_string(struct Node head) {
    char* result;
    struct Node* temp = head;
    int length = 0, index = 0;

    while (temp != NULL) {
        length++;
        temp = temp->next;
    }

    result = (char)malloc((length + 1)  sizeof(char));

    temp = head;
    while (temp != NULL) {
        result[index++] = temp->data + '0';
        temp = temp->next;
    }
    result[length] = '\0';

    return result;
}

int main() {
    struct Node head = (struct Node)malloc(sizeof(struct Node));
    struct Node second = (struct Node)malloc(sizeof(struct Node));
    struct Node third = (struct Node)malloc(sizeof(struct Node));

    head->data = 1;
    head->next = second;
    second->data = 2;
    second->next = third;
    third->data = 3;
    third->next = NULL;

    char* str = list_to_string(head);
    printf("Linked list as a string: %s\n", str);

    free(head);
    free(second);
    free(third);
    free(str);

    return 0;
}