《从零开始的C语言生活》综合使用字符串函数
#include <stdio.h> #include <string.h> //字符串函数所需要的文件引入 int main() { char password[7]="secret"; char userInput[81]; printf("Input password:"); scanf("%s",userInput); if(!strcmp(password,userInput)){//如果一样返回0,所以这里用非来满足条件 比较str1 str2的字符串大小,str1大就返回正值,str1小返回负值,相同返回0值 printf("Correct!"); } else if(strlen(password)>strlen(userInput)){ //strlen 用来获取字符串长度的函数 printf("userinput<password!"); } else printf("user input > password"); }
Tips:鼠标经过代码时会出现工具栏,工具栏上方有一键复制代码的功能哦~天云网络培训,专注于网络空间安全相关培训,并提供相关课程的在线培训 报名微信 tyedu1
天云网络培训 » 《从零开始的C语言生活》综合使用字符串函数
天云网络培训 » 《从零开始的C语言生活》综合使用字符串函数