c - Incompatible pointer error, fiscal code calculator -
i'm trying create fiscal code calculator algorithm.
here's code:
#include<stdio.h> #include<string.h> int main() { int day,month,year,i; char mo; char name[1][30]; char surname[1][30]; char a,b,c,d,e,h,l,m,p,r,s,t; printf("insert birthday day: "); scanf("%d",&day); printf("insert birthday month: "); scanf("%d",&month); printf("insert birthday year (last 2 numbers): "); scanf("%d",&year); /*month calculator*/ switch(month) { case 1: mo="a"; break; case 2: mo="b"; break; case 3: mo="c"; break; case 4: mo="d"; break; case 5: mo="e"; break; case 6: mo="h"; break; case 7: mo="l"; break; case 8: mo="m"; break; case 9: mo="p"; break; case 10: mo="r"; break; case 11: mo="s"; break; case 12: mo="t"; break; } printf("your fiscal code is: %d%c%d",year,mo,day); }
in every case of switch receive same error: incompatible pointer integer conversion assigning 'char' 'char[2]'.
where error?
thanks all!
you trying assign char
s char*
s. mo
char
, strings surrounded in double quotes("
) char*
s ending \0
. use single quotes('
) denote characters.
change
switch(month) { case 1: mo="a"; break; case 2: mo="b"; break; case 3: mo="c"; break; case 4: mo="d"; break; case 5: mo="e"; break; case 6: mo="h"; break; case 7: mo="l"; break; case 8: mo="m"; break; case 9: mo="p"; break; case 10: mo="r"; break; case 11: mo="s"; break; case 12: mo="t"; break; }
to
switch(month) { case 1: mo='a'; break; case 2: mo='b'; break; case 3: mo='c'; break; case 4: mo='d'; break; case 5: mo='e'; break; case 6: mo='h'; break; case 7: mo='l'; break; case 8: mo='m'; break; case 9: mo='p'; break; case 10: mo='r'; break; case 11: mo='s'; break; case 12: mo='t'; //break; not needed }
Comments
Post a Comment