2

I have the following piece of code, which when I compile it, I get:

smash.c:22 error: syntax error before "char"

I don't understand where the problem is. (line 22 is marked by /*22*/ in the error message, but line numbers do not appear in the code). How can I correct this error?

/*some comments...*/
/*some more comments...*/

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>

#include "dir_handling.h"
#include "var_handling.h"



#define     MAXLENGTH           80        

void error_print (char* str)
{
    /*22*/ char *error_message=(*char)malloc((strlen(str)+strlen("smash error: > \"\"\n")+1)*sizeof(char));
    strcpy (error_message,"smash error: > \"");
    strcat(error_message,str);
    strcat(error_message,"\"\n");
    perror (error_message);
    free (error_message);
    // printf ("smash error: > \"%s\"\n",str);
}
...
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
SIMEL
  • 8,745
  • 28
  • 84
  • 130

2 Answers2

3

(*char) should be (char *).

Andrey Vlasovskikh
  • 16,489
  • 7
  • 44
  • 62
3

It should be (char*), as in:

char *error_message=(char*)malloc( etc...

But note: it is good practice not to cast the return of malloc...

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541