Error at start time string [closed]

0
#include<stdio.h>
int main(){
    int numero,unidade,dezena,centena;
    char *unidades[]={"I","II","III","IV","V","VI","VII","VIII","IX"}; 
    char *dezenas[]={"X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
    char *centenas[]={"C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
    scanf("%d",&numero);
    unidade=(numero%100)%10;
    dezena=(numero%100)/10;
    centena=numero/100;
    if (centena){
        printf("%s",centena[centena-1]);
    }
    if (dezena){
        printf("%s",dezena[dezena-1]);
    }
    if (unidade){
        printf("%s",unidade[unidade-1]);
    }
    printf("\n");
    return 0;
}

So, I was trying to make the URI 1960, which consists of converting a number into a decimal base for a number in Roman numerals, but I'm having trouble printing the string . p>

The following error occurs:

  

subscripted value is neither array nor pointer nor vector            printf ("% s", centena [1]);

The same goes for tens and units.

    
asked by anonymous 25.04.2018 / 01:10

1 answer

2

The problem is that you forgot s in the vector names:

#include <stdio.h>

int main() {
    char *unidades[] = {"I", "II", "III" ,"IV", "V", "VI", "VII", "VIII", "IX"}; 
    char *dezenas[] = {"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
    char *centenas[] = {"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
    int numero;
    scanf("%d", &numero);
    int unidade = (numero % 100) % 10;
    int dezena = (numero % 100) / 10;
    int centena = numero / 100;
    if (centena) printf("%s", centenas[centena - 1]);
    if (dezena) printf("%s", dezenas[dezena - 1]);
    if (unidade) printf("%s", unidades[unidade - 1]);
}
    
25.04.2018 / 01:20