Stack implemented using a single linked list I am studying data structures and I have implemented a stack using a linked list.  

stack.h  

#ifndef STACK_H
#define STACK_H

#include &lt;stdbool.h&gt;

typedef char StackElement;

typedef struct stack_CDT *Stack;

Stack stack_init();

void stack_destroy(Stack s);

bool stack_is_empty(Stack s);

void stack_push(Stack s, StackElement elem);

StackElement stack_pop(Stack s);

#endif


stack.c  

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdbool.h&gt;
#include &lt;assert.h&gt;
#include "stack.h"

typedef struct node {
    StackElement data;
    struct node *next;
} Node;

Node *node_create(StackElement data)
{
    Node *new = malloc(sizeof *new);
    new-&gt;data = data;
    new-&gt;next = NULL;
    return new;
}

void node_insert(Node **node_ref, Node *new)
{
    if (new == NULL)
        return;

    new-&gt;next = *node_ref;
    *node_ref = new;
}

void node_delete(Node **node_ref)
{
    if (*node_ref == NULL)
        return;

    Node *next = (*node_ref)-&gt;next;
    free(*node_ref);
    *node_ref = next;
}

void list_delete(Node **head_ref)
{
    while ((*head_ref) != NULL)
        node_delete(head_ref);
}

typedef struct stack_CDT {
    Node *top;
} StackCDT;

StackCDT *stack_init()
{
    StackCDT *new = malloc(sizeof *new);
    new-&gt;top = NULL;
    return new;
}

void stack_destroy(StackCDT *s)
{
    list_delete(&amp;(s-&gt;top));
    free(s);
}

bool stack_is_empty(StackCDT *s)
{
    return s-&gt;top == NULL;
}

void stack_push(StackCDT *s, StackElement elem)
{
    Node *new = node_create(elem);
    node_insert(&amp;(s-&gt;top), new);
}

StackElement stack_pop(StackCDT *s)
{
    if (stack_is_empty(s)) {
        fprintf(stderr, "Can't pop element from stack, stack is empty.\n");
        exit(1);
    }

    StackElement elem = s-&gt;top-&gt;data;
    node_delete(&amp;(s-&gt;top));
    return elem;
}


stacktest.c  

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include "stack.h"

#define MAX_STR_LEN 100

void stacktest()
{
    printf("Enter a string(not more than %d characters): ", MAX_STR_LEN);
    char input[MAX_STR_LEN + 1];    
    fgets(input, sizeof input, stdin);
    char *pos;
    if ((pos = strchr(input, '\n')) != NULL)
        *pos = '\0';

    Stack stack = stack_init();
    for (char *c = input; *c; c++)
        stack_push(stack, *c);

    printf("Popped characters are: ");
    while (!stack_is_empty(stack))
        printf("%c", stack_pop(stack));
    printf("\n");

    stack_destroy(stack);
}

int main()
{
    stacktest();
    return 0;
}


Is my implementation all right?
No, your implementation is broken:

You forgot to check whether allocation succeeded.



Reviewing your code, you are going way overboard following the "small methods"-mantra in your library-code:

While the Single responsibility principle means every function should do one thing, and only one thing, the size of each task should be properly chosen.

Too little, and the function isn't a useful abstraction, using, writing and remembering it takes more effort than it saves.
(The performance-cost may be negligible (or even non-existent), if it is inlined. Consider marking it static to promote inlining and avoid exporting.)

Too much, and reusability and composability suffer.



Header:


I would avoid a typedef for the element-type. What does it buy you?
Using an opaque pointer is a good idea allowing you to replace the implementation with something more performant later. So, well done there.
Consider leaving the parameter-name out of the declaration when it doesn't make it more descriptive.
You should add a variation on stack_push which signals success, so a caller can opt in to handling failure gracefully:

bool stack_tryPush(Stack, StackElement);

Some more useful additions:

StackElement stack_peek(Stack);
StackElement stack_replace(Stack, StackElement);



Sourcefile:


You should re-order your includes: Always include the header you are implementing first, then all other headers, sorted for consistency (use the IDE's sorting-macro).
That way, you will know that your header is self-sufficient and you didn't forget a crucial dependency.
There's abort() for abnormal termination. Consider writing a helper-function if you need to output an error-message and abort in multiple places:

static void die(const char* message);

All your internal functions should not have external linkage, for performance and correctness reasons: Mark them inline.
Putting next first is more common, and possibly slightly more efficient. Also, for a single value value is more idiomatic than data.
Is there any reason why your typedef-name and struct-tag aren't quite equal? That's ittitating.
node_create is a waste: It's literally more work to read, write, and use it than leaving the single use inline.
As a rule of thumb, extracting 2 lines into their own function is a net loss of readability. Exceptons are often-used pieces of code.

Actually, that can be generalized to all your internal functions, with the possible exception of node_delete, which is marginal.
There are two kinds of precondition-checks:


Sanity checks, verifying that the programs logic is sane. These are normally disabled in a release build for performance reasons, and use assert().
Tests of untrusted input. How far you can/should/must trust an API's user must be decided in each case. It's your task as API-designer to decide how much you should penalize your users to catch egregious abuse even in release-mode, and whether there's also a debug-mode.
But there's no excuse for making your internal helper-functions re-assert preconditions even in release-mode.

As you are using C99 (see &lt;stdbool.h&gt;), you can use compound-literals to set all members of a struct-type comfortably even after initialization.

void stack_push(StackCDT *s, StackElement value)
{
    Node *new = malloc(sizeof *new);
    *new = (Node){s-&gt;top, value};
    if(!new) die("Failed to allocate a new node.");
    s-&gt;top = new;
}



Testprogram:


return 0; is implicit in main since C99.
Any reason for extracting your whole main into a different function?