Subj : Re: strange string pointer to strings...? To : borland.public.cpp.borlandcpp From : maeder Date : Thu Sep 29 2005 01:00 am "mujeebrm" writes: > #include > #include > #include > > int main(void) > { > > /* this does not make sense to me that when i keep adding rows and columns > of strings to this array of pointers to strings it just keeps > going on, any explanation for this ? The program is severely flawed in several ways. It suspiciously looks like a school assignment, so I won't give you the solution. > */ > char *s[][5]= { > "one","qwer", > "two", "rewq", > "three", "qwer", > "four", "rewq", > "five", "qwertttt", > " ", " " > }; Please read the other post of today by myself in this group. It is a bad idea to have pointers to char (non-const) pointing at string literals. Then 5 is obviously too short for "three" and "qwertttt". > char **sp=0,w[10]; > int c; > > do > { > gets(w); A call to this function is *always* a bug. The function must *absolutely never* be used, because it doesn't check the size of the buffer. Have a look at fgets() as a replacement. > sp = (char **)s;//why r we supposed to init this pointer to pointer to > strings > // again and again thru the loop You can't have a pointer to pointer to char point to an array of arrays of char. The types are not compatible. The endless loop in your program is a consequence of this incompatibility. .