首页 > 解决方案 > 在 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);

标签: arrayscstringif-statementspace

解决方案


推荐阅读