0

Debug

I'm not able to identify the error If it is 1 then Monday must be printed. It 2 then Tuesday https://code.sololearn.com/cb2U0ikJCWp1/?ref=app

3rd Apr 2019, 3:40 PM
Mallika Das
Mallika Das - avatar
3 Antworten
+ 5
Change code at line 4 to char* str; The char array was a local variable, it can't be transferred outside the function. Loniie on second thought, I think you might be better to follow suggestion from Anna , I'm not so sure what I gave you was technically correct, I just passed in what I found to be working : )
3rd Apr 2019, 4:06 PM
Ipang
+ 3
You can't assign strings to variables like that, use strcpy(str, "Monday") etc. instead (you'll need to #include <string.h>). I'm not sure if functions can return strings (=char arrays, they probably can't). You can use a pointer to a global variable instead: char *day_str[100]; // global void day(int n) { switch (n) { case 1: strcpy(day_str, "monday"); // change global variable //str="monday"; break; case 2: //str="tuesday"; break; default: //str="invalid"; break; } } int main() { int n=0; scanf("%d",&n); day(n); // set global variable printf("%s",day_str); // and print it }
3rd Apr 2019, 4:17 PM
Anna
Anna - avatar
+ 1
Thank you thank you so much
3rd Apr 2019, 4:21 PM
Mallika Das
Mallika Das - avatar