Re: return a string




Nascimento wrote:
> int i;
> char tralha[num];
>
> tralha = "#";
> for( i = 0; i < num-1; i++ )
> strcpy(tralha, strcat(tralha,"#"));

Oh, no! Look what's happening here! You are trying to copy chars into
the tralha[] array without using the proper notation. This is bad.

What you want to do is use array substript notation or pointer
arithmetic. Substript is by far easier for the beginner.

tralha[0] = '#'; /* Use single quotes for char */
for( i = 1; i < num-1; i++ ) /* i=1, not 0 (see above) */
tralha[i] = '#'; /* again, copy a char only */
tralha[i] = '\0'; /* don't forget the terminator! */

You don't need (or want) strcpy or strcat when you are building an
array from scratch.

.