[A89] Re: c trouble


[Prev][Next][Index][Thread]

[A89] Re: c trouble



I should also say that you can end your list of strings with a null pointer 
just as well as a pointer to an empty string. Well almost as well.

char *string_list[]={"foo","bar",NULL};

is about as easy to use and saves a byte. (just one), but either way is a 
considerable improvement over passing the number of strings as an argument.


>From: sqrt_-1@juno.com
>Reply-To: assembly-89@lists.ticalc.org
>To: assembly-89@lists.ticalc.org
>Subject: [A89] c trouble
>Date: Mon, 1 Sep 2003 21:08:52 -0500
>
>I'm having trouble with arrays of strings.  What I'm trying to do is make
>a function that will cycle through a list of options.  The options are in
>an array of strings.
>
>void main(void)
>{
>char options[3][6] = {"yes  ", "no   ", "maybe"};
>...
>scroll_field(3, options, (INT_POINT){18*8,0}, GrWhite(), GrBlack());
>...
>}
>
>The relevant parts of the scroll_field definition are:
>
>int scroll_field(int number_of_options,
>  char option_str[number_of_options][],
>  INT_POINT location, GrColor fgc, GrColor bgc)
>{
>  int option = 1;
>  ...
>  GrTextXY(location.x, location.y, option_str[option - 1], fgc, bgc);
>  ...
>}
>
>
>The function GrTextXY() takes a string as the 3rd argument.
>
>As you've probably guessed, this isn't for a 89 program.  I'm using
>DJGPP.  It gives the error "arithmetic on pointer to incomplete type"
>twice on the line with GrTextXY().
>
>I found the source of a program with a similar function.  They used a
>buffer and strcpy, so I tried that:
>
>int scroll_field(int number_of_options,
>  char option_str[number_of_options][],
>  INT_POINT location, GrColor fgc, GrColor bgc)
>{
>  int option = 1;
>  char buffer[81];
>  ...
>  strcpy(buffer, option[option - 1]);
>  GrTextXY(location.x, location.y, buffer, fgc, bgc);
>  ...
>}
>
>As expected, the GrTextXY() line was fine and the strcpy() line produced
>an error: "subscripted value is neither array nor pointer".  Someone
>please help me.
>
>________________________________________________________________
>The best thing to hit the internet in years - Juno SpeedBand!
>Surf the web up to FIVE TIMES FASTER!
>Only $14.95/ month - visit www.juno.com to sign up today!
>

_________________________________________________________________
Get MSN 8 and enjoy automatic e-mail virus protection.  
http://join.msn.com/?page=features/virus