Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

What are projects to be made if I added a native .C file to empty project and want to build .lib file which will be linked with CPP project with /clr option to build .exe ??

But my native code is giving basic errors like,
it is not even compiling this code ..

..//

int g = 1;
g++;
....///

compiler is giving error as
Error C2105: '++' needs l-value

///HERE is whole code starts

C#
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
int ch;
char Y_N;
void EASY()
{
int colr, arr, i,j,r, b[6];
char col[]={'R','Y','BG','B','P','G'};
clrscr();
textcolor(25);
gotoxy(3,5);
cprintf("Guess the hidden codes\n");
gotoxy(3,6);
cprintf("You only have fourteen tries.\n");
showcolors();
for(i=0;i<6;i++)
{
    int r=rand()%sizeof(col);
    printf("%c ",col[r]);
}
printf("\n");
for(i=1;i<=14;i++)
{printf("\nGuess No. [%d]: ",i);
for(j=0;j<6;j++)
{scanf("%d",&b[j]);
{if(col[0]==b[0])
arr++;
else
if(col[1]==b[1])   /*What should i put in the position of col[1] and*/
col++;           /*b[1] to compare the random code that was generated*/
else               /*by the program and the characters that that was*/
if(a[0]==b[2])    /*inputted by the player of the game?*/
col++;
else
if(a[0]==b[3])
col++;
else
if(a[0]==b[4])
col++;
else
if(a[0]==b[5])
col++;}
{if(a[1]==b[1])
arr++;
else
if(a[1]==b[0])
col++;
else
if(a[1]==b[2])
col++;
else
if(a[1]==b[3])
col++;
else
if(a[1]==b[4])
col++;
else
if(a[1]==b[5])
col++;}
{if(a[2]==b[2])
arr++;
else
if(a[2]==b[0])
col++;
else
if(a[2]==b[1])
col++;
else
if(a[2]==b[3])
col++;
else
if(a[2]==b[4])
col++;
else
if(a[2]==b[5])
col++;}
{if(a[3]==b[3])
arr++;
else
if(a[3]==b[0])
col++;
else
if(a[3]==b[1])
col++;
else
if(a[3]==b[2])
col++;
else
if(a[3]==b[4])
col++;
else
if(a[3]==b[5])
col++;}
{if(a[4]==b[4])
arr++;
else
if(a[4]==b[0])
col++;
else
if(a[4]==b[1])
col++;
else
if(a[4]==b[2])
col++;
else
if(a[4]==b[3])
col++;
else
if(a[4]==b[5])
col++;}
{if(a[5]==b[5])
arr++;
else
if(a[5]==b[0])
col++;
else
if(a[5]==b[1])
col++;
else
if(a[5]==b[2])
col++;
else
if(a[5]==b[3])
col++;
else
if(a[5]==b[4])
col++;}
gotoxy(60,11);
printf("Arrangements: %d\tColors: %d",arr,col);
{if(arr==6)
i=15;
printf("You have decoded the code. Congratulations!");}
}}
}
showcolors()
{
    gotoxy(3,8);
    printf("Colors are:  ");
    gotoxy(3,9);
    textcolor(RED);
    cprintf("[R]Red");
    gotoxy(11,9);
    textcolor(3);
    cprintf("[BG]BlueGreen");
    gotoxy(26,9);
    textcolor(YELLOW);
    cprintf("[Y]Yellow");
    gotoxy(37,9);
    textcolor(GREEN);
    cprintf("[G]Green");
    gotoxy(47,9);
    textcolor(9);
    cprintf("[B]Blue");
    gotoxy(56,9);
    textcolor(5);
    cprintf("[P]Purple");
    printf("\n");
}
main()
{
clrscr();
printf("MASTERMIND GAME\n\n");
printf("Choose Difficulty\n[1] EASY\n[2] NORMAL\n[3] HARD\n\n");
printf("Your Choice: ");
scanf("%d",&ch);
if(ch==1)
EASY();
else
if(ch==2)
printf("*");
else
if(ch==3)
printf("*");
else
printf("\nWRONG KEY!");
getch();
}


////---------------------- C code ends


Please help !!!!!
Posted
Updated 6-Sep-10 23:38pm
v3
Comments
Richard MacCutchan 7-Sep-10 4:08am    
The above two statements should compile, perhaps there is something else in your source that is wrong. Please post a bit more of the code in error.
Ketan D Kulkarni 7-Sep-10 5:16am    
//This is whole code which was producing above and a lots of errors ...file is //saved as .C

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#include<ctype.h>

int ch;
char Y_N;
void EASY()
{
int colr, arr, i,j,r, b[6];
char col[]={'R','Y','BG','B','P','G'};
clrscr();
textcolor(25);
gotoxy(3,5);
cprintf("Guess the hidden codes
");
gotoxy(3,6);
cprintf("You only have fourteen tries.
");
showcolors();
for(i=0;i<6;i++)
{
int r=rand()%sizeof(col);
printf("%c ",col[r]);
}
printf("
");
for(i=1;i<=14;i++)
{printf("
Guess No. [%d]: ",i);
for(j=0;j<6;j++)
{scanf("%d",&b[j]);
{if(col[0]==b[0])
arr++;
else
if(col[1]==b[1]) /*What should i put in the position of col[1] and*/
col++; /*b[1] to compare the random code that was generated*/
else /*by the program and the characters that that was*/
if(a[0]==b[2]) /*inputted by the player of the game?*/
col++;
else
if(a[0]==b[3])
col++;
else
if(a[0]==b[4])
col++;
else
if(a[0]==b[5])
col++;}
{if(a[1]==b[1])
arr++;
else
if(a[1]==b[0])
col++;
else
if(a[1]==b[2])
col++;
else
if(a[1]==b[3])
col++;
else
if(a[1]==b[4])
col++;
else
if(a[1]==b[5])
col++;}
{if(a[2]==b[2])
arr++;
else
if(a[2]==b[0])
col++;
else
if(a[2]==b[1])
col++;
else
if(a[2]==b[3])
col++;
else
if(a[2]==b[4])
col++;
else
if(a[2]==b[5])
col++;}
{if(a[3]==b[3])
arr++;
else
if(a[3]==b[0])
col++;
else
if(a[3]==b[1])
col++;
else
if(a[3]==b[2])
col++;
else
if(a[3]==b[4])
col++;
else
if(a[3]==b[5])
col++;}
{if(a[4]==b[4])
arr++;
else
if(a[4]==b[0])
col++;
else
if(a[4]==b[1])
col++;
else
if(a[4]==b[2])
col++;
else
if(a[4]==b[3])
col++;
else
if(a[4]==b[5])
col++;}
{if(a[5]==b[5])
arr++;
else
if(a[5]==b[0])
col++;
else
if(a[5]==b[1])
col++;
else
if(a[5]==b[2])
col++;
else
if(a[5]==b[3])
col++;
else
if(a[5]==b[4])
col++;}
gotoxy(60,11);
printf("Arrangements: %d Colors: %d",arr,col);
{if(arr==6)
i=15;
printf("You have decoded the code. Congratulations!");}
}}

}
showcolors()
{
gotoxy(3,8);
printf("Colors are: ");
gotoxy(3,9);
textcolor(RED);
cprintf("[R]Red");
gotoxy(11,9);
textcolor(3);
cprintf("[BG]BlueGreen");
gotoxy(26,9);
textcolor(YELLOW);
cprintf("[Y]Yellow");
gotoxy(37,9);
textcolor(GREEN);
cprintf("[G]Green");
gotoxy(47,9);
textcolor(9);
cprintf("[B]Blue");
gotoxy(56,9);
textcolor(5);
cprintf("[P]Purple");
printf("
");
}
main()
{
clrscr();
printf("MASTERMIND GAME

");
printf("Choose Difficulty
[1] EASY
[2] NORMAL
[3] HARD

");
printf("Your Choice: ");
scanf("%d",&ch);
if(ch==1)
EASY();
else
if(ch==2)
printf("*");
else
if(ch==3)
printf("*");
else
printf("
WRONG KEY!");
getch();
}
Sandeep Mewara 7-Sep-10 8:15am    
Additional Comments:
What happens if you rename your .c file .cpp?

1 solution

..//
int g = 1;
g++;....///
This code not compiling? It can be because of only few reasons:

  1. g is #defined as a macro!
  2. g is actually declared to be const
  3. g is in a class, and the method is const


And FYI, a .C file cannot be compiled with /clr.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900