Prezado Circle,
Monday, November 25, 2002, 12:30:53 PM, voce escreveu:
> Prezado Circle,
> Monday, November 25, 2002, 12:10:01 PM, voce escreveu:
>> When you initialize a string this way, the data is constant, and therefore
>> cannot be modified. You could try something like this instead:
>> char chmap[5][10]; /* 5 rows, 10 columns */
>> strcpy(chmap[0], "-----\r\n");
>> Then later you can do this:
>> strcpy(chmap[0], "-A-A-\r\n");
>> or
>> chmap[0][1] = 'A';
> Yeah.. I tryed this but there's a problem... I need something like
> "char *blabla[]" 'cause its size is variable...
> The first char is only a template. After I need to alter its characters
> and add more... So, the size of each line can change and I cant declare
> it like a char blabla[size][size]...
After a war against C I solved this doing the following:
------------------
char *map_repl(char *c, size_t pos, int chr) {
char buf[8000];
size_t i;
for (i=0; i<strlen(c); i++) {
if (i==pos)
buf[i] = chr;
else
buf[i] = c[i];
}
buf[i]='\0';
c = buf;
return c;
}
int main() {
char *map[] = {
"-----\r\n",
"-----\r\n",
"-----\r\n"
};
map[0] = map_repl(map[0],2,'a');
printf("%s",map[0]);
return 0;
}
---------------------
Thanks for the help! :D
--
Marcelus Trojahn
trojahn@lagosnet.com.br
Suporte Técnico de Internet
http://www.lagosnet.com.br - lagosnet@lagosnet.com.br
--
+---------------------------------------------------------------+
| FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
| Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
| Newbie List: http://groups.yahoo.com/group/circle-newbies/ |
+---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 06/25/03 PDT