嵌入式第九天学习

第九天学习

课外知识

ai的简洁循环

c 复制代码
const char *prompt[3] = {"请输入你的名字:", "请输入你的学号:", "请输入你的成绩:"};

for (int i = 0; i < 3; ++i) {
    printf("%s", prompt[i]);
    scanf("%31s", massage[time1][i]);   // %31s 防止写越界
}
c 复制代码
#include <stdio.h>

int main(void) {
    int n;
    printf("请输入元素个数:");
    if (scanf("%d", &n) != 1 || n <= 0 || n > 1000) {
        fprintf(stderr, "非法个数!\n");
        return 1;
    }

    int a[n];           // C99 可变长数组(VLA)
    printf("请输入 %d 个整数:", n);
    for (int i = 0; i < n; ++i) {
        if (scanf("%d", &a[i]) != 1) {
            fprintf(stderr, "输入错误!\n");
            return 1;
        }
    }

    /* 打印验证 */
    for (int i = 0; i < n; ++i)
        printf("%d ", a[i]);
    puts("");
    return 0;
}

一句话总结:

给 %c/% 等不自动跳过空白的格式加前导空格 是最简单、最通用的"吃掉换行符"技巧。

c 复制代码
scanf(" %c", &ch);   // %c 前面有空格

查询系统

#include <stdio.h>

#include <string.h>

#include <windows.h>

char name11032;

char password11032;

char name\[\] = {0};

char password\[\] = {0};

int num = 0;

char massage10332;

void menu()

{

printf("*********\n");
printf("***** 1.创建账户 \n");
printf("
2.登录账户 \n");
printf("
3.查询信息 \n");
printf("
4.退出 \n");
printf("
\n");

}

void creat()

{

printf("正在创建账户,请稍等。 \n");

Sleep(1000);

while (1)

{

printf("请输入账号:");

scanf(" %s", name1num);

printf("%s", name1num);

printf("请输入密码:");

scanf(" %s", password1num);

printf("账号为:%s ,密码为:%s \n", name1num, password1num);

num++;

break;

}

}

void getin()

{

int time1 = num;

int time2 = num;

int flag = 0;

while (1)

{

err:

printf("请输入账号:\n");

scanf(" %s", name);

// while (getchar() != '\n')

// {}

while (time1 + 1)

{

int true1 = strcmp(name, name1time1);

if (true1 == 0)

{

break;

}

time1--;

if (time1 == -1)

{

printf("账号错误请重新输入! \n");

goto err;

}

}

break;

}

while (1)

{

err1:

printf("请输入密码: \n");

scanf(" %s", password);

while (getchar() != '\n')

{

}

while (time2 + 1)

{

int true2 = strcmp(password, password1time2);

if (true2 == 0)

{

break;

}

time2--;

}

if (time2 == -1)

{

printf("密码错误请重新输入! \n");

goto err1;

}

break;

}

for (int i = 0; i < 3; i++)

{

if (i == 0)

{

printf("请输入你的名字:");

scanf(" %s", massagetime1i);

continue;

}

if (i == 1)

{

printf("请输入你的学号:");

scanf(" %s", massagetime1i);

continue;

}

if (i == 2)

{

printf("请输入你的成绩:");

scanf(" %s", massagetime1i);

continue;

}

}

printf("您查询的序号为:%d \n", time1);

}

void found()

{

printf("请输入你的查询序号:");

int a = 0;

scanf(" %d", &a);

for (int i = 0; i < 3; i++)

{

switch (i)

{

case 0:

printf("您的名字为:%s \n", massageai);

break;

case 1:

printf("您的学号为:%s \n", massageai);

break;

case 2:

printf("您的成绩为:%s \n", massageai);

break;

default:

break;

}

}

}

int main(int argc, char const *argv\[\])

{

复制代码
menu();
int chose = 0;
printf("请输入你的选择:");
while (1)
{
    scanf("%d", &chose);
    if (chose == 1)
    {
        creat();
        Sleep(1000);
        menu();
        continue;
    }

    if (chose == 2)
    {
        getin();
        Sleep(1000);
        menu();
        continue;
    }
    if (chose == 3)
    {
        found();
        Sleep(1000);
        menu();
        continue;
    }
    if (chose == 4)
    {
        printf("下次再见!");
        break;
    }
    else
    {
        printf("选择错误,请重新输入:");
        continue;
    }
}
return 0;

}

相关推荐
xian_wwq3 分钟前
【学习笔记】深度认知系列-第16讲-提示词工程
人工智能·笔记·学习
洛阳纸贵6 分钟前
MATLAB-matlab基础知识
学习·算法·matlab
落羽的落羽11 分钟前
【AI】快速理解AI应用的相关名词概念
linux·c++·人工智能·python·计算机网络·算法
刚入门的大一新生13 分钟前
Linux-进程控制
linux·运维·服务器·c++
上火的金鱼妹18 分钟前
K8S基础组件作用和关系整理
linux·运维·服务器·kubernetes
Nil20828 分钟前
leetcode 17电话号码的字母组合
算法·leetcode·职场和发展
Vcaker28 分钟前
Linux学习25-harbor私有仓库部署
linux·运维·学习
刃神太酷啦32 分钟前
Redis 进阶核心:持久化 (RDB/AOF)、事务与主从复制全解析----《Hello Redis!》(5)
linux·c语言·数据库·c++·redis·缓存·bootstrap
留白_1 小时前
【tableau入门学习】5、筛选器、参考线和集
学习·tableau
编程的一拳超人1 小时前
DeepSeek Harness Linux/macOS/Windows 本地下载、启动与模型配置指南
linux·windows·macos·deepseek