Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!cs.dal.ca!aucs!840445m From: 840445m@aucs.uucp (Alan McKay) Newsgroups: comp.lang.c Subject: scanf( "%s" ) question Message-ID: <1990Feb28.183815.6756@aucs.uucp> Date: 28 Feb 90 18:38:15 GMT Reply-To: 840445m@aucs.UUCP (Alan McKay) Organization: School of Computer Science, Acadia Univ., Nova Scotia Lines: 28 eat this you nasty line-eater!! ------------------------------------------ I actually have 2 questions both of which are related. This first is just a matter of syntax ... I want to declare an array of 20 strings of length 5, and I am doing the following: char array[20][5]; /* is this correct? */ Ok, that is the easy one. Now, each of these 20 strings gets read from the keyboard and I am using 'scanf' to do it. However, I want to ensure that only the first 4 characters get read into the string ( saving the last space for \0, of course ). I am not sure how to do this. Is there some way I can specify that in my format statement? I tried "%4s" but that does not seem to do it. scanf( "%4s", array[0] ); /* to read in the first string */ What is happening now is that if more characters are entered they end up over-writing array[1] .. [2] ... etc depending upon how man are entered. I am using Turbo-C (what version??) but it is absolutely mandatory that the solution be totally portable since I will be re-compiling on a number of other systems, and running the program there as well. Oh, and finally, I do not read this group so could you please reply via e-mail rather than a follow-up? Thank you very much.