el_froggy
Gebruiker
- Lid geworden
- 21 jun 2005
- Berichten
- 114
Beste,
ik wou mijn C wat oefenen door een programma te schrijven dat RGB inleest en omzet naar hexadecimaal.
nu heb ik eigenlijk nog maar 1 les C gehad, en ken ik blijkbaar niets af van getaltypes..
dit is mijn code:
en dit zijn de fouten die mijn compiler me geeft:
kan iemand me uitleggen hoe ik dit opgelost kan worden?
alvast bdankt
ik wou mijn C wat oefenen door een programma te schrijven dat RGB inleest en omzet naar hexadecimaal.
nu heb ik eigenlijk nog maar 1 les C gehad, en ken ik blijkbaar niets af van getaltypes..
dit is mijn code:
Code:
#include<stdio.h>
#include<string.h>
int main(void)
{
int rood, groen, blauw;
printf("Rood: ");
scanf("%d", &rood);
printf("Groen: ");
scanf("%d", &groen);
printf("Blauw: ");
scanf("%d", &blauw);
if (rood > 255 || rood < 0 || groen > 255 || groen < 0 || blauw > 255 || blauw < 0 )
{
printf("De waardes moeten tussen 0 en 255 liggen\n");
return 1;
}
else
{
char R = omzet(rood);
char G = omzet(groen);
char B = omzet(blauw);
strcat(R, G);
strcat (R, B);
printf ("de hexadecimale waarde is %c", R);
}
return 0;
}
char[5] omzet(int kleur)
{
int kleur_a = kleur, kleur_b = kleur;
kleur_a = kleur_a / 16;
kleur_b = kleur_b % 16;
char kleur_1;
char kleur_2;
switch (kleur_a)
{
case 10:
kleur_1 = "A";
break;
case 11:
kleur_1 = "B";
break;
case 12:
kleur_1 = "C";
break;
case 13:
kleur_1 = "D";
break;
case 14:
kleur_1 = "E";
break;
case 15:
kleur_1 = "F";
break;
default: kleur_1 = kleur_a;
}
switch (kleur_b)
{
case 10:
kleur_2 = "A";
break;
case 11:
kleur_2 = "B";
break;
case 12:
kleur_2 = "C";
break;
case 13:
kleur_2 = "D";
break;
case 14:
kleur_2 = "E";
break;
case 15:
kleur_2 = "F";
break;
default: kleur_2 = kleur_b;
}
strcat (kleur_1, kleur_2);
return kleur_1;
}
en dit zijn de fouten die mijn compiler me geeft:
Code:
Compiler: Default compiler
Bezig met uitvoeren van gcc.exe...
gcc.exe "C:\kiran\C\hex.c" -o "C:\kiran\C\hex.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\kiran\C\hex.c: In function `main':
C:\kiran\C\hex.c:27: warning: passing arg 1 of `strcat' makes pointer from integer without a cast
C:\kiran\C\hex.c:27: warning: passing arg 2 of `strcat' makes pointer from integer without a cast
C:\kiran\C\hex.c:28: warning: passing arg 1 of `strcat' makes pointer from integer without a cast
C:\kiran\C\hex.c:28: warning: passing arg 2 of `strcat' makes pointer from integer without a cast
C:\kiran\C\hex.c: At top level:
C:\kiran\C\hex.c:37: error: syntax error before '[' token
C:\kiran\C\hex.c:41: error: initializer element is not constant
C:\kiran\C\hex.c:41: warning: data definition has no type or storage class
C:\kiran\C\hex.c:42: error: initializer element is not constant
C:\kiran\C\hex.c:42: warning: data definition has no type or storage class
C:\kiran\C\hex.c:47: error: syntax error before "switch"
C:\kiran\C\hex.c:92: warning: parameter names (without types) in function declaration
C:\kiran\C\hex.c:92: error: conflicting types for 'strcat'
C:\kiran\C\hex.c:92: error: conflicting types for 'strcat'
C:\kiran\C\hex.c:92: warning: data definition has no type or storage class
C:\kiran\C\hex.c:93: error: syntax error before "return"
Uitvoering voltooid
kan iemand me uitleggen hoe ik dit opgelost kan worden?
alvast bdankt