+ 1
Can someone help me to solve the problem in my C code
if I input 1 or 2, the compiler prints the result four times, I think the problem is on the main function. if you know why this happened please explain the problem. https://code.sololearn.com/ch44x76UxA16
2 ответов
+ 1
When you input 1 or 2 , you are calling this ChoseOne1(Num); function 4 times.. actually no use. You can remove line 20 and else part. Which does nothing..
edit: Zakarya Meddahi
just use like :
if(strcmp(ChoseOne1(Num), "\0") != 0)
{
strcpy(string, ChoseOne1(Num));
printf("%s\n", string);
}
instead of
strcpy(string, ChoseOne1(Num));
if(strcmp(ChoseOne1(Num), "\0") != 0)
{
printf("%s\n", string);
}
else if(strcmp(ChoseOne1(Num), "\0") == 0)
{
ChoseOne1(Num);
}
hope it helps.
+ 4
Put your code in the code playground, and share the link. That will make it easier to debug.