Sponsored Content
Full Discussion: help with hangman
Top Forums UNIX for Dummies Questions & Answers help with hangman Post 302380970 by sainis on Wednesday 16th of December 2009 07:05:36 PM
Old 12-16-2009
thanks friend for help

i have read many books and i read yet the last i try to study is The Complete Reference Unix" from Obserne

one thought is wrote this code to replace the '-' with right character is using the substr
is using this code to calculate the length
Code:
wordlength=${#word}
awk -v var1=$charact 'BEGIN {for (i=1;i<=wordlength;i++){A[i]=substr(var1,i,1)};for (i=1;i<=wordlength;i++){print i,T[i]}}' /dev/null

do you believe that may work or what you recommend to chance in this code to run correctly

---------- Post updated at 07:05 PM ---------- Previous update was at 06:58 PM ----------

using this code i split the word to a table

Code:
awk -v var1=$word 'BEGIN {FS="';split (var1,T); (for i=1;i<=length(var1);i++) {print i,T[i]}}' /dev/null

using this code i replace the characters with - - -
for example if the word was bedroom with this code appear - - - - - - -
Code:
awk -v var1=$word 'BEGIN {for (i=1;i<=length(var1);i++) {printf("%s","-")};print}' /dev/null

i want to read a character using this command
Code:
read charact

and if this character included for example to bedroom display this character for example

the word is :bedroom
script appear: ------- 7- depends on word length
while i read charact: press e
i want the script appear this -e----m

i think i can do that with substr

i use bash
 

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Hangman written in Bash. Suggestions please...

qwertyuiop (1 Reply)
Discussion started by: rorey_breaker
1 Replies

2. Shell Programming and Scripting

Script for Hangman Game

Any ideas on whats the best way to form a hangman game via bash shell. (0 Replies)
Discussion started by: immyakram
0 Replies

3. Shell Programming and Scripting

Hangman Script

Hello everyone, im just having some problem forming a script for a hangman script. The question states: The object this excercise is for u to write a script that emulate the classic game hangman. The object of this game is for a user to try and guess a word which has been generated by the... (1 Reply)
Discussion started by: immyakram
1 Replies
Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSuUser(Contributed Perl DocumPerl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr(3)

NAME
Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr - Use 4-argument "substr" instead of writing "substr($foo, 2, 6) = $bar". AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
Conway discourages the use of "substr()" as an lvalue, instead recommending that the 4-argument version of "substr()" be used instead. substr($something, 1, 2) = $newvalue; # not ok substr($something, 1, 2, $newvalue); # ok The four-argument form of "substr()" was introduced in Perl 5.005. This policy does not report violations on code which explicitly specifies an earlier version of Perl (e.g. "use 5.004;"). CONFIGURATION
This Policy is not configurable except for the standard options. SEE ALSO
"substr" in perlfunc (or "perldoc -f substr"). "4th argument to substr" in perl5005delta AUTHOR
Graham TerMarsch <graham@howlingfrog.com> COPYRIGHT
Copyright (c) 2005-2011 Graham TerMarsch. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.3 2014-06-09 Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr(3)
All times are GMT -4. The time now is 07:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy