How to transform into a lowercase a value of a struct?

0

The next function should turn variables into lowercase and then compare them. I've tried converting before, but also bugou . Arithmetic use of pointers next to variables of struct . Pointer points to struct .

How to fix the error in the following code snippet:

struct registro{ 
    char conta[50], senha[50], usuario[50];
}atual[1000], *ptr;

int verifica_usuario(int *ptr){
    int i;
    for(i = 0; i < *ptr; i++) {
        if(strcmp(tolower(atual[*ptr].usuario), tolower(atual[i].usuario)) == 0) {
                return 0;
        }
    }
    return 1;
}
    
asked by anonymous 02.11.2017 / 04:01

1 answer

1

Although there are insensitive functions, it is not part of the pattern. To run anywhere create your own function:

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

int stricmp(char const *s1, char const *s2) {
   while (1) {
        int res = tolower(*s1) - tolower(*s2);
        if (res != 0 || !*s1) return res;
        s1++;
        s2++;
    }
}

int main(void) {
    printf("%d\n", stricmp("aaa", "AAA"));
    printf("%d\n", stricmp("aaa", "aaa"));
    printf("%d\n", stricmp("aaa", "AAB"));
    printf("%d\n", stricmp("abb", "AAB"));
}

See running on ideone . And in Coding Ground . Also I put it in GitHub for future reference .

Then check the member of the structure I think you already know. Follow the recommendations of the comments, the algorithm is more complicated than it should. And there are other bugs in it, but that's another problem.

    
02.11.2017 / 12:09