The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
null string matching in sed? Allasso Shell Programming and Scripting 6 05-30-2008 08:44 PM
String matching mpang_ Shell Programming and Scripting 3 07-28-2006 06:45 AM
sed problem - replacement string should be same length as matching string. amangeles Shell Programming and Scripting 4 01-11-2006 06:11 AM
SED: Matching a string with whitespace? cstovall Shell Programming and Scripting 1 06-07-2005 04:32 PM
matching alphanumeric string sskb Shell Programming and Scripting 4 12-12-2001 10:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-18-2008
nehaquick nehaquick is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 7
Exclamation Matching string

Hello,
i have a program where i have to get a character from the user and check it against the word i have and then replace the character in a blank at the same position it is in the word.

Last edited by nehaquick; 02-18-2008 at 04:45 PM..
  #2 (permalink)  
Old 02-18-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Is it a game?

Code:
WORD="nasty"

while true
do
   echo -e "Input a char: \c"
   read CHAR
   CHARS="${CHARS}${CHAR}"
   echo "$WORD" | sed "s/[^${CHARS}]/-/g"
done
  #3 (permalink)  
Old 02-18-2008
earnstaf earnstaf is offline
Registered User
  
 

Join Date: May 2007
Posts: 113
Quote:
Originally Posted by robotronic View Post
Is it a game?

Code:
WORD="nasty"

while true
do
   echo -e "Input a char: \c"
   read CHAR
   CHARS="${CHARS}${CHAR}"
   echo "$WORD" | sed "s/[^${CHARS}]/-/g"
done
That's a cool way to go about doing a hangman type game. Should be pretty easy to have it pick a random dictionary word to use for $WORD and then give a certain number of guesses and decrement the count each time a wrong letter is guessed. Thanks for killing time for me at work on a Holiday
  #4 (permalink)  
Old 02-18-2008
nehaquick nehaquick is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 7
Thumbs up

dear robotronic

thanks a lot for the reply. its working correctly but its still asking for another character even when the word is there. i think more needs to be put in the while condition. apart from that as evident its a game, i have to keep a count of no of guesses by the user and as well as the lives the user lost(wrong guesses). i dont know where to update those variables in the current loop. thanks in advance

Last edited by nehaquick; 02-18-2008 at 05:02 PM..
  #5 (permalink)  
Old 02-18-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool with a few additions...

Code:
WORD="nasty"
cnt=0
known="n"
while [ $known = "n" ]
do
   echo -e "Input a char: \c"
   read CHAR
   CHARS="${CHARS}${CHAR}"
   ((cnt = cnt + 1))
   disp=$(echo "$WORD" | sed "s/[^${CHARS}]/-/g")
   echo $disp
   if [ $WORD = $disp ]
      then
      known="y"
   fi
done 
echo $cnt" guesses"
  #6 (permalink)  
Old 02-19-2008
nehaquick nehaquick is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 7
Lightbulb

Thanks Joeyg,
the program is working fine but another requisite was that i have to count the no of wrong guesses as well and deduct it from the no of lives given to the user. these lives are user defined. the control should move out of the while loop as soon as the word is found or the no of lives are finished. even otherwise if the word is guessed correctly it should show that in how many attempts(which the program is doing) and how many loss of lives the user has guessed it. thanks in advance
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0