扫描多个名称时出错(字符串矩阵)

时间:2018-11-17 20:31:23

标签: c++ c arrays string char

好吧,这是错误,我尝试读取每个不同的名称,但我不能只读取其他名称

This is what happens, what's the error?

int main(void)
{
// Variables declaration
int i, j, n, len;
char names[25][100];

// The amount of names
printf("enter the number of names: ");
scanf("%i", &n);

// Scanning all the names
for (i = 0; i < n; i++)
{
    printf("name %i: ", i+1);
    gets(names[i]);
}

// Upper them
for (i = 0; i < n; i++)
{
    for (j = 0, len = strlen(names[i]); j < len; j++)
    {
        names[i][j] = toupper(names[i][j]);
    }
}

// Printing them
for (i = 0; i < n; i++)
{
    printf("name %i: %s\n", i+1, names[i]);
}
}

0 个答案:

没有答案