Reputation: 35
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
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
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
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