View Single Post
  #61 (permalink)  
Old 25th August, 2005, 04:26 PM
Gizmo's Avatar
Gizmo Gizmo is offline
Chief BBS Administrator
 
Join Date: May 2003
Location: Webb City, Mo
Posts: 16,178
Send a message via ICQ to Gizmo Send a message via AIM to Gizmo Send a message via MSN to Gizmo Send a message via Yahoo to Gizmo Send a message via Skype™ to Gizmo

use this:

Code:
scanf("%127s", this_is_a_string);
The '%127s' tells scanf to accept up to a maximum of 127 characters of input before terminating. It puts a terminating null char at the end of the string, which is why you use 127 instead of 128 (the size of the char array). Note that there is no guarantee that there will be 127 characters in the array, only that scanf will accept up to that many. If the user hits the enter key before the 127th character, then you will get input up to that many characters of input. You can use strlen() to determine exactly how many characters were entered if you are interested.

Code:
if("%s", this_is_a_string > 30) goto "printf", this_is_a_string;
Is not valid 'C' code. If anything, it looks like a combination of 'C' and Basic.

Also, as a matter of style, it is best to avoid goto. There is nothing you can do with goto in 'C' that you can't accomplish using another language construct, and in 99.999% of the cases, you will have code that is easier to maintain as well. (Not saying you can't use goto; there are some very rare situations where it makes sense. But you should ask yourself if using goto is the best way to solve your problem.)
Reply With Quote