1) You are traversing the string in the wrong way.
A for
is executed while its logical condition, the second parameter, is true:
for (inicializacao ; condicao; passo)
Right?
Now think: if your i
starts with 0
, it will never be greater than the length of your nome
string. So, you need to switch to:
for (i = 0; i < strlen(nome); ++i)
2) Vectors in C
(so, strings, which are character vectors as well) are already pointers implicitly. So, to use the string name in the paraBaixo
function, you do not use *
. Also, when you do nome[i] + 32
, you need to save it back into nome[i]
itself, otherwise the result is 'thrown out':
void paraBaixo(char *nome)
{
int i;
for(i=0;i<strlen(nome);i++)
{
nome[i] = nome[i] + 32;
}
}
3) Now, just more 'stylistic' questions:
or
fgets(nome, 25, stdin);
In the end, I recommend something like:
#include<stdio.h>
#include<string.h>
void paraBaixo(char *nome)
{
int i;
for(i=0;i<strlen(nome);i++)
{
nome[i] = nome[i] + 32;
}
}
int main()
{
char nome[25];
printf("Insira um nome: \n");
fgets(nome, 25, stdin);
paraBaixo(nome);
printf("Nomo com tudo em minusculo: %s\n",nome);
return 0;
}