开发者

syntax error before "char" in C

开发者 https://www.devze.com 2023-02-23 04:52 出处:网络
I have the following piece of code, which when I compile it, I get: smash.c:22 error: syntax error before \"char\"

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 <err开发者_C百科no.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);
}
...


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...


(*char) should be (char *).

0

精彩评论

暂无评论...
验证码 换一张
取 消