3 Replies - 1027 Views - Last Post: 21 December 2006 - 04:07 PM Rate Topic: -----

#1 CrematedPumpkin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-December 06

Question concerning printf/scanf and %s flag

Posted 20 December 2006 - 05:48 PM

I'm not sure about this, but is there a way to do something similar to how you can have the user input a number and if it equal to whatever it does the desired thing?
Here's what I mean, since that was a little unclear:
	int gea;						  
  
	printf( "Numberness " );  
	scanf( "%d", &age );				 
	if ( gea < 100 ) {				  
	 printf ("Blah!\n" ); 
  }
  else if ( gea == 100 ) {			
	 printf( "Blah\n" );	   
	 getchar();


And so forth. Is there a certain thing you have to do with text strings? I tried to do something like this and it didn't work.

Is This A Good Question/Topic? 0
  • +

Replies To: Question concerning printf/scanf and %s flag

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 415
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Question concerning printf/scanf and %s flag

Posted 20 December 2006 - 08:00 PM

Depends on the situation.

Can you post the code you tried before and we will see if we can help you?
Was This Post Helpful? 0
  • +
  • -

#3 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 289
  • View blog
  • Posts: 1,898
  • Joined: 25-October 06

Re: Question concerning printf/scanf and %s flag

Posted 21 December 2006 - 12:12 AM

View PostCrematedPumpkin, on 21 Dec, 2006 - 12:48 AM, said:

I'm not sure about this, but is there a way to do something similar to how you can have the user input a number and if it equal to whatever it does the desired thing?
Here's what I mean, since that was a little unclear:
	int gea;						  
  
	printf( "Numberness " );  
	scanf( "%d", &age );				 
	if ( gea < 100 ) {				  
	 printf ("Blah!\n" ); 
  }
  else if ( gea == 100 ) {			
	 printf( "Blah\n" );	   
	 getchar();


And so forth. Is there a certain thing you have to do with text strings? I tried to do something like this and it didn't work.

you can read a string into a char[] array using the %s conversion specification and then use strcmp() to compare them, see
http://www.cplusplus...ing/strcmp.html
Was This Post Helpful? 0
  • +
  • -

#4 CrematedPumpkin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-December 06

Re: Question concerning printf/scanf and %s flag

Posted 21 December 2006 - 04:07 PM

Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1