> if (ch->clandivision == 1) > divbuf = clan_table[ch->clan].division_one_name; (line 1202) > else > divbuf = clan_table[ch->clan].division_two_name; (line 1204
strcpy()! >-----Original Message----- >From: Jeremy Hill [mailto:[EMAIL PROTECTED] >Sent: Friday, June 14, 2002 4:11 AM >To: [email protected] >Subject: Pointers, strings, and clowns (no clowns) > > >Okay, here's a plea for help. > >Goal: To print the players' clan division, if applicable, out >using sprintf. > >struct clan_type >{ > ... > char *division_one_name; > char *division_two_name; > ... >}; > >That's how the divisions are laid out in the struct. 'ch' has a >clandivision field added to it--0 = not in a division, 1 = >division 1, 2 = >division 2. Question 1: Is there a better way of >accomplishing this? This >system isn't very flexible. However, this isn't the >relatively important >question; that one follows: > >Here's where I'm running into problems: > >char *divbuf[MAX_STRING_LENGTH]; >... > > if (ch->clandivision > 0 && ch->clandivision < 3) > { > if (ch->clandivision == 1) > divbuf = clan_table[ch->clan].division_one_name; (line 1202) > else > divbuf = clan_table[ch->clan].division_two_name; (line 1204) > } >... > >act_comm.c:1202: incompatible types in assignment >act_comm.c:1204: incompatible types in assignment > >Originally, I had divbuf not be a pointer, but that also >failed. What I'm >trying to do is to copy the name of the division to a buffer, >which will be >printed as part of the following sprintf: > \/ > sprintf(buf, "%s [(%d) %s] %s: '%s'", > clan_table[ch->clan].who_name, ch->clanrank, divbuf, ch->name, >argument); > >Should I just change the struct definition of *division_one_name and >*division_two_name to not be pointers? I need not really even >need to copy >the name to a buffer, I suppose I could instead have three different >sprintfs for each situation ('clan_table[ch->clan].division_one_name, >two_name, or none), but that doesn't help me in figuring out >pointers and C >in the long run. > >I'm sure the optimal solution is relatively easy, but I just >can't see it >(like all newbie programmers, pointers are like a programming >language in >and of their own to me). > >I appreciate your help. > >Thanks, >Jeremy Hill > > > >-- >ROM mailing list >[email protected] >http://www.rom.org/cgi-bin/mailman/listinfo/rom >

