When there is a lot of error I do not try to look for error, I rewrite right, even though it still does not solve all problems and not optimizing as much as it can. And I do not know if I understand the problem, it is not described and the code may have indicated something else:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define QTD_NOMES 2
#define TAM_NOME 30
int soChars(char *nome, int tamanho) {
for (int i = 0; i < tamanho; i++) {
if (isdigit(nome[i]) != 0) {
printf("\nNome invalido!\nDigite apenas letras!\n");
return 0;
}
}
return 1;
}
void leValidaNome(char *nome) {
while (1) {
printf("Informe seu nome:");
scanf(" %[^\n]s", nome);
int tamanho = strlen(nome);
if (tamanho == 0) printf("\nNome invalido!\nDigite algo!\n");
else if (soChars(nome, tamanho)) return;
}
}
int main() {
char nomes[QTD_NOMES][TAM_NOME];
for (int i = 0; i < QTD_NOMES; i++) leValidaNome(nomes[i]);
for (int j = 0; j < strlen(nomes[0]); j++) nomes[0][j] = toupper(nomes[0][j]);
for (int i = 1; i < QTD_NOMES; i++) {
for (int j = 0; j < strlen(nomes[i]); j++) nomes[i][j] = tolower(nomes[i][j]);
}
printf("\n%s\n%s", nomes[0], nomes[1]);
}
See running on ideone . And no Coding Ground . Also put it in GitHub for future reference .
Part of the problem is that the code is confusing and overly complicated, can be simpler and better written.
The allocation was done inefficiently and wrongly, since it allocated space for all words of main()
just use this address for any write function.
I have simplified the function loop that reads names separating validation if everything is a character, so it eliminates flag , which is a pest, so when it is valid, just the function.
It is possible that failure to initialize loop variables has caused some error, so I always speak to declare variables and then use not declare before.