String vector condition error in C

Asked

Viewed 103 times

0

I’m having a hard time with a specific exercise:

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <windows.h>
#include <ctype.h>
#include <string.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
    setlocale(LC_ALL, "portuguese");

    char nome[0][50], hoje[0][50];

    printf("Digite o nome do local: ");

    scanf("%s", &nome[0]);

    printf("Digite o dia: ");

    scanf("%s", &hoje[0]);
    toupper((char)hoje);

    if((hoje[0] == "SEGUNDA") && (strlen(nome) < 100)){
        printf("Nome é: %s\n", nome[0]);
        printf("Hoje é: SEGUNDA\n");
    }else if((hoje[0] == "TERÇA") && (strlen(nome) < 100)){
        printf("Nome é: %s\n", nome[0]);
        printf("Hoje é: TERÇA\n");
    }else{
        printf("Dia da semana nao é SEGUNDA e nem TERÇA");
    }

    system("pause >> null");
    return 0;
}

when compiled, it does not consider if and pause the program after inputs and reversing the condition if(!(hoje[0] == "SEGUNDA") && (strlen(nome) < 100)) with the ! he printa, but goes out for ex: Seu nome é: SEGUNDA, Hoje é: SEGUNDA it replaces the name variable for today when it prints the output, what can it be ? the address or allocation ? Thank you.

  • It is a shame to be a duplicate, because there are more errors than those cited. Such as converting a string to maiscula and misspelling the badly made matrix.

  • I could use the string conversion to uppercase as toupper((char)today[0]); in case ? I don’t understand why the output is stopping before either. I’m new to C

  • Exactly, one of the errors will be exactly that, this question should not have been closed. I will try to put a code to solve this. int i=0; while (hoje[0][i]!='\0') {&#xA; hoje[0][i] = toupper((unsigned char) hoje[0][i]);&#xA; i++;&#xA; } the function toupper only converts ONE character and not the string, so you have to scroll through each character in the string and convert to more

  • Thank you for the good will to help me Fabio ! I understood the loop to turn it into an automatic capitalization, will it go like this before you get paroled ? for(int i =0; i< strlen(&today[0]); i++){ toupper((char)today[0][i]); }

  • The professor of the college put the exercises with mistakes, so that we correct and identify them, but I think this one is a little more complicated than expected.

  • Yes, you can too, but only strlen(hoje[0]) without the &. The rest of the code can be read in the links that were placed here. You should compare strings with the strcmp()

  • Ahh right, good ta accusing this here [Warning] Passing argument 1 of 'strlen' from incompatible Pointer type, and this here no for [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode, I’m using Dev - C++ by Compiler, which is not very good either but is what it uses =/

  • strlen(nome) is the address of the head office. strlen(nome[0]) is correct, you will have to get the code, because the rest of things are simple

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.