Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: tImmaY
hey, i'm getting an error in this C program i'm writing, but i'm not sure as to why. the error that i'm getting is telling me that i'm trying to assign a value incorrectly, such as: 1 = a; but i'm not trying to assign an int, i'm trying to assign a char. i have the variable i want for the char declared global because i want to access it in other functions. so i have something like:
char current_level[20] = "", level = 1, ..;
...
...
if (level == 1)
{
current_level = "beginner";
}
else if (level == 2)
{
current_level = "intermediate";
...
}
...but Dev-C++ tells me:
error: incompatible types in assignmentand MSVC++ says:
error C2106: '=' : left operand must be l-valuewhat am i doing wrong?? thanks

char *current_level="", level='1';
...
if (level == '1') //note single quotes
{
current_level = "beginner";
}
or
char *current_level="";
int level=1;if (level == 1)
{
current_level = "beginner";
}

hmm.. i c.
why do the chars have to be pointers? also, its telling me: invalid initializer
for the line that has the declaration of current_level and level on it. any clues as to why?

In C:
#include <string.h>
int main()
{
char current_level[20] = "";
char level = 2;
if (level == 1)
{
strcpy(current_level,"beginner");
}
else if (level == 2)
{
strcpy(current_level, "intermediate");
}
return 0;
}In C++:
#include <string>
using namespace std;
int main()
{
string current_level;
char level = 2;
if (level == 1)
{
current_level = "beginner";
}
else if (level == 2)
{
current_level = "intermediate";
}
return 0;
}

![]() |
doubt in windows prog
|
Ansi c
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |