Archívum - Jún 17, 2012 - Fórum téma
C-ben char tömböt hogyan adok vissza egy függvényben?
char* TopOrBottom (char character, int width) {
char str[width];
str[0] = '*';
int i = 1;
for (i = 1; i < width - 1; ++i) {
str[i] = character;
}
str[width - 1] = '*';
str[width] = 0;
return str;
}
user@pc:~/dev/c/pprint$ gcc -Wall -W -Werror pprint.c -o pprint
pprint.c: In function ‘TopOrBottom’:
pprint.c:22:5: error: function returns address of local variable [-Werror]
cc1: all warnings being treated as errors
pprint.c: In function ‘TopOrBottom’:
pprint.c:22:5: error: function returns address of local variable [-Werror]
cc1: all warnings being treated as errors