【问题标题】:How to get an array of strings without using argv - CS50 pset2如何在不使用 argv 的情况下获取字符串数组 - CS50 pset2
【发布时间】:2017-06-27 19:50:55
【问题描述】:

我目前正在参加 CS50 哈佛课程,但遇到了问题集 2。 我制作了这个程序,它采用名称并打印首字母,它在命令行中采用名称。如何使用 get_string() 代替 argv,而 argc 非常不正统和草率,所以我可以提示用户给我她/他的名字。谢谢你。

#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>

int main(int argc, string argv[])
{

//How do I use Get_string() so I don't have to use argv and argc?? 


//iterate over strings on the vector (words)
    for (int i = 0; i < argc; i++)
    {
        //prints the 0 character of each string, use "toupper" to convert into capital letters
        printf("%c", toupper(argv[i][0]));

    }
    printf("\n");
}

【问题讨论】:

    标签: cs50


    【解决方案1】:

    使用数组, 假设有 10 个名字

    string name[10];
    for (int i = 0; i < 10; i++)
    {
        name[i] = get_string("Enter your name: /n");
    }
    

    【讨论】:

      猜你喜欢
      • 2012-05-10
      • 1970-01-01
      • 2018-06-06
      • 2019-06-11
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 2016-12-03
      • 1970-01-01
      相关资源
      最近更新 更多