Tokenize arithmetic expression in C This program tokenizes an arithmetic expression specified in infix notation. It is one of my personal projects and I would love to receive expert advice.
After compiling, you can run the program with one command-line argument:
$ tokenize &lt;arith_expr&gt;

This is an example of running the program:
$ tokenize &quot;3^2 + 4.5 * (-2 - 1)&quot;

The tokenizer currently supports these operators + - * / ^.
#include &lt;ctype.h&gt;
#include &lt;stdbool.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

/* Can store an operator or an operand */
struct token {
    char operator;
    float operand;
};

/* Check if given token is an operator */
bool is_operator(char token)
{
    if (token == '+' ||
        token == '-' ||
        token == '*' ||
        token == '/' ||
        token == '^')
        return true;
    else
        return false;
}

/* Remove all spaces from string */
void rmspaces(char *str)
{
    const char *dup = str;
    do {
        while (isspace(*dup))
            ++dup;
    } while (*str++ = *dup++);
}

/* Return first token of given arithmetic expression */
struct token *tokenize(char **expr)
{
    static bool op_allowed = false;
    struct token *token = malloc(sizeof *token);
    if (!token) {
        printf(&quot;Error: memory allocation failed&quot;);
        exit(EXIT_FAILURE);
    }

    if (op_allowed &amp;&amp; is_operator(*expr[0])) {
        token-&gt;operator = *expr[0];
        ++(*expr);
        op_allowed = false;
    } else if (!op_allowed &amp;&amp; *expr[0] == '(') {
        token-&gt;operator = *expr[0];
        ++(*expr);
    } else if (op_allowed &amp;&amp; *expr[0] == ')') {
        token-&gt;operator = *expr[0];
        ++(*expr);
    } else {
        char *rest;
        token-&gt;operand = strtof(*expr, &amp;rest);
        token-&gt;operator = '\0';
        if (*expr == rest) {
            printf(&quot;Invalid expression\n&quot;);
            exit(EXIT_FAILURE);
        }
        strcpy(*expr, rest);
        op_allowed = true;
    }

    return token;
}

/* Handle command line arguments */
int main(int argc, char *argv[])
{
    if (argc != 2) {
        printf(&quot;Usage:   %s &lt;arith_expr&gt;\n&quot;
            &quot;Example: %s \&quot;5 2 3 * +\&quot;\n&quot;,
            argv[0], argv[0]);
        exit(EXIT_FAILURE);
    }

    char *expr = argv[1];
    rmspaces(expr);
    struct token *token;
    while (expr[0] != '\0') {
        token = tokenize(&amp;expr);
        if (token-&gt;operator == '\0') // token is operand
            printf(&quot;%f\n&quot;, token-&gt;operand);
        else
            printf(&quot;%c\n&quot;, token-&gt;operator);
    }

    return EXIT_SUCCESS;
}
Your is_operator function can be rewritten as
return token == '+' || token == '-' || token == '*' || token == '/' || token == '^';

Much cleaner, in my opinion.

The program has a memory leak. Your tokenize function allocates a struct token on the heap, but the object is never freed.
Better yet, instead of returning a struct token*, just return a struct token. The struct certainly isn't large enough to warrant an allocation on the heap.

Instead of checking whether token is an operand by comparing operator to 0, use an enum.
typedef enum { 
       TokenType_Operator, 
       TokenType_Operand 
} token_type;

Then your token struct can consist of the token_type enum, and an union.
struct token
{
   token_type type;
   union {
       char operator;
       float operand;
   } data;
};

If you're using C11, you don't even need to name the union anything.

As a next step, try to implement a tokenizer that tokenizes in one pass. Right now, your tokenizer 1) removes whitespace (which involves a linear pass) and 2) copies of the rest of the string after the tokenizing an operand into the original buffer. If you have a large buffer, this could become a bottleneck.
A common way to implement a tokenizer is using a DFA (deterministic finite automata). In fact, a DFA is a starting point for most handwritten lexers.