void add()
{
char name[50], surname[50], usern[50];
int id, birth, amount;
printf("Enter your name, surname and your year of birth:\n");
scanf("%s %s %d", &name, &surname, &birth);
printf("Enter your ID, username and your total amount:\n");
scanf("%d %s %d", &id, &usern, &amount);
const char *pass1=function(usern);
}
const char *function (char usern[50])
{
char temp;
int i=0;
int j;
j = strlen(usern) - 1;
while (i < j)
{
temp = usern[i];
usern[i] = usern[j];
usern[j] = temp;
i++;
j--;
}
return usern;
}
I call 'add' from 'main' to print those things and then I call 'function' to return me the usern string but something goes wrong.
I get the error when compiling:
[Warning] initialization makes pointer from integer without a cast--> const char *pass1=function(usern);
[Error] conflicting types for 'function'--> const char *function (char usern[50])
const char *pass1? What is the expected output and what output are you getting? A broad statement like "something goes wrong" will likely get you no help. More details about the problem on the other hand will definitely help you nail the problem. :)function()before defining it. You can define the function before you use it, or add a function protoype before you use it:const char* function(char usern[50]);Also note @Bathsheba 's answer about possible undefined behaviour.