C Problem; Expected expression

Solved
siniko44 Posted messages 187 Status Membre -  
siniko44 Posted messages 187 Status Membre -
Hello,
I just started with C recently, and I'm encountering my first problems.
I created a small script for a game, here it is:

 #include <stdio.h> #include <stdlib.h> #include <string.h> int type, isFixe, val, val1, val2; char *typeHex; void jet(int type, int isFixe, int val1, int val2) { switch(type) { case 1: typeHex[2] = {'7','D'}; break; case 2: typeHex[2] = {'7','C'}; break; case 3: typeHex[2] = {'7','6'}; break; case 4: typeHex[2] = {'7','E'}; break; case 5: typeHex[2] = {'7','7'}; break; case 6: typeHex[2] = {'7','B'}; break; } if(isFixe == 1) { printf("Here is the roll to copy: %s#0#0#0#0d0+%d",typeHex,val1); } else { printf("Here is the roll to copy: %s#0#0#0#1d0+%d",typeHex,val2-1,val1-1); } } int main(int argc, char *argv[]) { printf("\tJet Creation Software by Psycko\n\n"); printf("==============================================\n\n"); printf("1. Vitality\t2. Wisdom\n3. Strength\t4. Intelligence\n5. Agility\t6. Luck\n\n"); printf("Enter the roll type number: "); scanf("%d",&type); printf("Fixed roll(1) or non-fixed roll(0)?"); scanf("%d",&isFixe); if(isFixe == 1) { printf("Value: "); scanf("%d",&val); jet(type,1,val,0); } else { printf("Value 1: "); scanf("%d",&val1); printf("Value 2: "); scanf("%d",&val2); jet(type,0,val1,val2); } printf("\n\n"); system("pause"); } 

Only the part in bold is concerned.
However, during compilation, the well-known Windows console returns:

test.c: In function 'jet':
test.c:12:23: error: expected expression before '{' token
test.c:13:23: error: expected expression before '{' token
test.c:14:23: error: expected expression before '{' token
test.c:15:23: error: expected expression before '{' token
test.c:16:23: error: expected expression before '{' token
test.c:17:23: error: expected expression before '{' token

So I'm turning to you now in hopes of finding a solution.

Good night! :p

2 réponses

nicocorico Posted messages 846 Status Membre 138
 
Well, I don't know C, but if I'm not mistaken, you're putting 2 chars in one and that's where the error is;
Moreover, you could replace the Switch with an array indexed by the Type value, and it seems to me that you are redeclaring the variables type, val1, and val2...

The oak was also an acorn before it became an oak
1
Char Snipeur Posted messages 10112 Registration date   Status Contributeur Last intervention   1 331
 
you are working with strings, so just use the equal sign with quotes.
case 5:typeHex="77";
What you want to do with your pointer typeHex is unclear. The method I’m giving you makes typeHex point to a constant string, which seems to me the best solution since typeHex is a global variable.
--
True submission is when the slaves worry about the price of cotton.
Char Snipeur
0
siniko44 Posted messages 187 Status Membre 17
 
Thank you very much! :)
0