RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Returning Array from a function

Zidenbr

Sorceror
Returning Array from a function

Hello everyone. Im tryng to return array; from a function but its not working. Any ideas ?

Code:
char le(FILE *arq, char texto[50])
{
     texto = "";
     char c; int x=0;
     while(c!='#' && c!='}')
     {
       c = getc(arq);
       if(c!='#' && c!='}' && c!='{') {texto[x] = c;x++;}
     }     
     int tam = strlen(*texto); *texto[tam+1] = '\0';
     return texto; // COMPILER ERROR HERE <<
}
 

Smjert

Sorceror
Well, if you had read the compiler error i think you would know where the error is.
Anyway you're returning a char array (char[]) while your function accept a char as return.
You have to put char[] in the function return parameter.
 

remnant

Wanderer
A better question might be to ask why you are returning a value you pass as a parameter to the method? Why not just pass the parameter by reference or pointer?
 

Jeff

Lord
remnant;849854 said:
A better question might be to ask why you are returning a value you pass as a parameter to the method? Why not just pass the parameter by reference or pointer?

Yes, that would be more optimal and more C++ oriented.
 
Top