为什么for循环中的strlen变量没有获得数据类型?

问题描述

我发现了使 this 更长的代码(不是i

elif user_input == "a":
    while True:
        try:
            add_item = input("What item would you like to add? ").lower()
            if not re.match("^[a-z,A-Z]*$",add_item):
                print("ERROR: Only letters A-Z are allowed!")
                continue
            elif len(add_item) < 1 or len(add_item) > 20:
                print("Item name is too long,only a maximum of 20 characters are allowed!")
                continue
            else:
                item_amount = int(input("How many of these would you like to add? "))
                shopping_list[add_item] = item_amount
                print(f"{item_amount}x {add_item.title()} added to the shopping list.\n")
            while True:
                try:
                    add_more = input("Would you like to add more items? (y/n): ").lower()
                    if add_more == "y":
                        break
                    elif add_more == "n":
                        break
                except TypeError:
                    print("ERROR: Expected y or n in return! Try again!.\n")
                    break
        except ValueError:
            print("\nERROR: Amount must be an integer! Try adding an item again!\n")

...放入 this 的更多简写代码(注意n变量):

for (int i = 0; i < strlen(string1); i++)
{
    printf("%c",string1[i]);
}

我的问题是,为什么不是“ size_t n = strlen(string1)”?为什么不给n数据类型?

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...