C入门

作者: 23b57d72cde7 | 来源:发表于2018-03-21 19:22 被阅读0次

字符串

  • 1.strcmp
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void login();
void main(){
login();
    system("pause");
}
void login(){
    printf("请输入用户名:");
    char userName[20];
    gets(userName);
    printf("请输入密码:");
    char passWord[20];
    gets(passWord);
    if(!strcmp(userName,"admin")&&!strcmp(passWord,"123456")){
        printf("登陆成功\n");
    }else{
    printf("登录失败\n");
    }
}
  • 2.strlen
char a[]="小明";
    int i = strlen(a);
    int j = strlen("黄晓明");
    printf("%d\n",i);
    printf("%d\n",j);
  • 3.strcat
        char source_string[] = "is very good";
    char target_string[30] = “zzsxt";
    strcat(target_string,source_string);
    printf("\n 源字符串 = %s", source_string);
    printf("\n 目标字符串 = %s\n", target_string);

相关文章

网友评论

      本文标题:C入门

      本文链接:https://www.haomeiwen.com/subject/qzhnqftx.html