I am new to coding and at my university we are learning C and C++ currently.
I have a problem with my C code. I want the code to say which day of the week it is when I enter a date. I get multiple errors with CodeBlocks.
I have to make an extra function for the "zeller's congruency".
I am not very sure how to get a string or a character from an other function.
I get the warning: "warning: assignment makes integer from pointer without a cast" at all cases of the switch. And in my main function I get the warning: "warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]"
header.h
int ta, mo, ja, h ,q ,m ,k , j;
char zk(int, int, int) ;
main.c
#include <stdio.h>
#include <stdlib.h>
#include "header.h"
int main()
{
int tt, mm, jj;
printf("Geben Sie das Datum ein: ");
scanf("%i %i %i", &tt, &mm, &jj);
printf("\n");
char *p = zk(tt, mm, jj);
printf("%s", *p);
return 0;
}
zellerskongruenz.c
#include <stdio.h>
#include <stdlib.h>
#include "header.h"
char zk(int ta, int mo, int ja)
{
if (mo == 1){mo = 13; ja--; }
if (mo == 2){mo = 14; ja--; }
q = mo;
k = ja % 100;
j = ja / 100;
h = ta + ((q+1)*13)/5 + k + k/4 + j/4 - 2*j;
h = h % 7;
char *wochentag;
switch(h)
{
case 0 : *wochentag = "Samstag"; break;
case 1 : *wochentag = "Sonntag"; break;
case 2 : *wochentag = "Montag"; break;
case 3 : *wochentag = "Dienstag"; break;
case 4 : *wochentag = "Mittwoch"; break;
case 5 : *wochentag = "Donnerstag"; break;
case 6 : *wochentag = "Freitag"; break;
}
return wochentag;
}
I am very thankful for anyone who tries to help me.
char zk(...toconst char * zk(...,char *wochentag;toconst char *wochentag;, all*wochentagto bewochentagandprintf("%s", *p);to beprintf("%s", p);.int main(void)in C.int ta, mo, jadefined in the header are useless, as they appear inzk()'s parameter list and with this are hidden. And the remainingh ,q ,m ,k , j;should better be defined locally tozk(), at least from the code you show there is no need to define them globally.