C语言字符串复制,否则

时间:2018-09-26 18:31:44

标签: c

SCNDisableWideGamut

我正在创建一个程序,该程序应该是包含车费,舱位和总计的旅费。它现在运行了,唯一的问题是目标中的if else语句,我需要2个字符,当我输入其他目标代码(例如,kl,bk或tp)时,它仅在hk中输出该语句,其余部分则不输出

1 个答案:

答案 0 :(得分:0)

您可能希望将HTML CODE ---------- <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title></title> </head> <body> <!--this is a simple fieldset with the dropboxes put in them--> <fieldset> <legend>Select your fruit!</legend> <form class="" action="tree.php" method="post"> <select name="Color"> <option value="Blank"></option> <option value="Red">Red</option> <option value="Purple">Purple</option> <option value="Yellow">Yellow</option> </select> <select name="Size"> <option value="Blank"></option> <option value="Small">Small</option> <option value="Medium">Medium</option> <option value="Large">Large</option> </select> <select name="Shape"> <option value="Blank"></option> <option value="Round">Round</option> <option value="Square">Square</option> <option value="Elipse">Elipse</option> </select> <input type="submit" /> </form> </fieldset> </body> </html> 替换为strcpy

strcmp会将文本“ HK”复制到strcpy(desti, "HK")中,此函数将成功执行,并且由于desti返回指向目标的指针,它将是一个非零值,它将执行每次都是if语句。

strcpy的手册页

请注意,strcpy相等时返回0。

有关strcmp的更多信息

还请注意

  • 您无法将strcmp放入strcpy(desti, "HK");中,因为您没有为空终止符分配空间。您将必须执行char desti[2];如果您希望将其用作字符串。