Cannot read string types properly.

Hello everyone. I am having issues using my counters to count the upper case, lower case, numbers, digits, and special caracters of my program. It looks like this:
#include <stdio.h>
#include <cstring>
#include <cctype>

int main(){
char nom[20], nombre[20];
int nomm=0, i=0, cont=0, may=0, min=0, esp=0, num=0, digit=0;
printf("Ingrese dos nombres. \n");
gets(nom);
gets(nombre);

printf("\nEvaluando nombres %s y %s.\n", nom, nombre);
strcat(nom, nombre);
printf("\n %s ", nom);

for(i=0; i<20; i++){ //issue stars here
if(!nom[i]){
nomm=i; }}

for(i=0;i<nomm;i++){
if(isalpha(nom[i])){
if(isupper(nom[i])) may++;
else min++;}
if(isalnum(nom[i])) num++;
if(isdigit(nom[i])) digit++;
else esp++; } //carac especiales not right, issue upto here

printf("\n Hay %d letras mayusculas, %d letras minusculas, %d caracteres especiales, %d numeros, %d digitos... \n", may, min, esp, num, digit);
}



As you can see, issue is with the counter. I write different frases with diffrent caracters and the numbers I receive back are very random.
Any help appreciated.
I would write the for loop like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
for (i = 0; nom[i] != '\0'; i++) 
{
  if (isupper(nom[i])) 
  {
    may++;
  }
  else if (islower(nom[i]))
  {
    min++;
  }
  else if (isalnum(nom[i])) 
  {
    num++;
  }
  else if (isdigit(nom[i]))
  {
    digit++;
  }
  else 
  {
    esp++;
  }
} 

Also it's better to use fgets instead of gets.
https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used
Topic archived. No new replies allowed.