1
I’m trying to reverse one string through a function only that it is giving error, however I do not know where it is wrong.
Right below is my code.
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
char troca(char nome[100], char nome1[100]);
int main(void)
{
char nome[100];
printf("Informe o nome para ser invertida :");
scanf("%s", nome);
printf("%s\n", troca(nome));
system("pause");
return 0;
}
char troca(char nome[100], char nome1[100])
{
int c = 0, i;
for(i = strlen(nome) - 1; i >= 0; i--)
{
nome[c] = nome[i];
c++;
}
nome1[c] = '\0';
return nome1[c];
}
Should not be name1[c] = name[i]; instead of name[c] = name[i];
– Sveen
and Return name1;
– Sveen
and should be "exchange char* (" instead of "exchange char("
– Sveen
exchange has two parameters and you are only passing 1
– Sveen
and string. h is not being used
– Sveen
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero