arrays - 在 C 中的数组的 if 语句的保护中使用空格
问题描述
我在编程中迈出了第一步,我试图制作一个程序,将您的用户名作为输入并将其作为输出打印出来。我想实现一个if 语句,当你在 scanf 中输入空格而不是字符时触发,但我似乎无法让它工作?字符数组是否可以做或不可能?谢谢你的帮助!
char username[20]; //declares a 20 chars array for the username to be stored
printf("\nPlease input your Username\nUsername:"); //asks for the username
scanf("%s", &username); //inserts username inside array "username"
if(username == ' '){ //supposedly the guard to my if
printf(("invalid imput"));
}
printf("%s",username);
解决方案
推荐阅读
- javascript - 从鼠标选择后未选择 jQuery UI 自动完成值
- wcf - wcf 托管在 Windows 服务和 httpbindings 中
- vba - Outlook 中用于密码保护附件文件的 VBA 插件
- javascript - 有没有办法使用 AJAX 将响应结果传递到另一个页面
- angular - Angular 和 FabricJS 类变量和事件
- c - 如何将另一个模块中的变量发送给函数?
- java - 在类型 [com.modelimpl.Modelmvcimpl] 上找不到属性 [fname]
- java - 尝试通过 JSON 查询从 openweathermap 获取数据时出现 FileNotFoundException
- excel - 直到循环执行缓慢 - 偏移和选择的替代方案?
- android - 查找设备的运动