Syntyche Ackerley
Syntyche Ackerley

Reputation: 35

Error: expected expression before ';' token char

I am experimenting with a code, I have looked through the other posts, but couldn't figure it out, could you help me out on why I am getting:

error: expected expression before ';' token
    char passwd[] = PASSWORD;

=========================

#include <stdio.h>
#include <string.h>

#define SIZE 100
#define PASSWORD ********

int main()
{
    int count = 0;
    char buff[SIZE] = " ";
    char passwd[] = PASSWORD;
...

Upvotes: 1

Views: 950

Answers (3)

Danny_ds
Danny_ds

Reputation: 11406

#define directive would define a label for some primitive value.

This implies your code will be interpreted as char passwd[]=********; in compile time.

You probably need quotes around the **:

#define PASSWORD "********"

Upvotes: 7

Box Box Box Box
Box Box Box Box

Reputation: 5241

The method in _Danny_ds_ and iharob's answer is correct. Also, you can use the strcpy function to copy the constant into the string passwd. Like This: strcpy (passwd, PASSWORD);

You can read this tutorial on strcpy.

NOTE: You also have to make the changes mentioned in the above answers.

Upvotes: 0

Iharob Al Asimi
Iharob Al Asimi

Reputation: 53006

PASSWORD has to be a string literal, in your code it's just multiple multiplication operators which is why the error message. To make it a string literal use double quotes like this

#define PASSWORD "********"

Upvotes: 2

Related Questions