السلام عليكم
عندي مشكلة في أستخدام الدالة strcmp حاولت أكثر من مره لكن كله أخطاء وهذا البرنامج بطريقتين مختلفتين مره باستخدام if ومره باستخدام switch
البرنامج يقوم بسؤال المستخدم ويختار المستخدم أما first أو second و third
#include<stdio.h>
#include<string.h>
void main()
{
char x[10];
printf("what is the capital of kuwait:\n");
printf("first) Doha\n");
print("second) kuwait\n");
printf("third) cairo\n");
printf("choice the correct answer:");
scanf("%s",x);
switch(x){
case(strcmp(x,"first")):
case(strcmp(x,"third")):
printf("\n wrong answer\n");
break;
case(strcmp(x,"second")):
printf("\ncorrect answer\n");
break;
default:
printf("\nwrong choice\n");
}
getch();
}#include<stdio.h>
#include<string.h>
void main()
{
char x[10];
printf("what is the capital of kuwait:\n");
printf("first) Doha\n");
print("second) kuwait\n");
printf("third) cairo\n");
printf("choice the correct answer:");
scanf("%s",x);
if(strcmp(x,"first")||srtcmp(x,"third"))
{
printf("\nwrong answer\n");
}
else if(strcmp(x,"second"))
{
printf("\ncorrect answer\n");
}
else{
printf("\nwrong choice\n");
}
getch();
}وعندي سؤال ثاني معنى الدالة return ؟ واستخداماتها وفوائدها ؟ بالإضافة لمثال يوضحها ؟
( لأني شفت أكثر من كتاب لكن ما فهمت المقصود من هذي الداله بالضبط )
وشكرا مقدما
