Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
I am trying to make a program that willl echo one statement if I type the correct word and echo somthing else if I input the wrong word, Ive tried ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2004
    Posts
    8

    newb programming question pls help!


    I am trying to make a program that willl echo one statement if I type the correct word and echo somthing else if I input the wrong word, Ive tried a couple things with the "read" command but I cant figure it out, any help would be great , thanks )

  2. #2
    Linux Guru
    Join Date
    Mar 2003
    Location
    Wisconsin
    Posts
    1,907
    You're using bash I assume?

    Code:
    if str1 = str2 then
     echo "correct\n"
    else
     echo"incorrect\n"
    fi
    Hope that helps!
    Jeremy
    Registered Linux user #346571
    "All The Dude ever wanted was his rug back" - The Dude

  3. #3
    Just Joined!
    Join Date
    Aug 2004
    Posts
    8
    Ok , sorry I think I am still lost, is str a command or are you using it as an example ? hehe sorry

  4. #4
    Just Joined!
    Join Date
    Aug 2004
    Posts
    8
    Here is another small example

    echo -n "word1: "
    read word1
    echo -n "word2: "
    read word2

    if test "$word1" = "$word2"
    then
    echo "Match"
    echo "End of program"

    else
    echo "No match"
    echo "End of Program"
    fi

  5. #5
    Just Joined!
    Join Date
    Aug 2004
    Posts
    8
    thanks that helped some, only thing is, when I give input from the keyboard it says the same thing no matter what I type.

    the result i get from that is the same I get from

    echo "word1"
    read word1
    echo "word2"
    read word2

  6. #6
    Just Joined!
    Join Date
    Aug 2004
    Posts
    8
    are those 4 lines your script? If it is you are not telling it to do much...

  7. #7
    Just Joined!
    Join Date
    Sep 2004
    Posts
    12
    Quote Originally Posted by jeremy1701
    You're using bash I assume?

    Code:
    if str1 = str2 then
     echo "correct\n"
    else
     echo"incorrect\n"
    fi
    Hope that helps!
    Jeremy
    hi there! i think what jeremy meant by that is something like these:

    Code:
    if "user input" = "desired input" then    #if the user input is same as what the program expects
     echo "correct\n"                                 #print that it is correct
    else                                                      
     echo"incorrect\n"                               #print that the user's input was wrong
    fi                                                          #end of if
    hoep

  8. #8
    Just Joined!
    Join Date
    Nov 2005
    Posts
    11
    plz tell how to get user input in C language in kernel because kernel does not suport getch() function.reply me as soon as possible and thanx in advance for helping me

  9. #9
    Linux User
    Join Date
    Aug 2005
    Location
    Italy
    Posts
    401

    Kernel programming...

    You can't use normal library routine in kernel programming (that's obvious because libraries are kernel based).

    However is very strange you want read input from kernel, because kernel has no terminal notion, so no input can be specified.

    One solution is to catch keyboard events, parse input data and compute what you want... but must ensure that no ones try to control you keyboard (however I don't know if it is possible!).

    Other solution is to create device driver wich read from a special file. Echoing standard output on the special file handled by your driver, data will be recieved into kernel by your module.

    Maybe you should read more about kernel programming (I suggest to start with Linux Kernel Module Programming guide)
    When using Windows, have you ever told "Ehi... do your business?"
    Linux user #396597 (http://counter.li.org)

  10. #10
    Just Joined!
    Join Date
    Nov 2005
    Posts
    11

    urgent problem plz help

    thanx for reply but can u guide me that how i can transfer data from kernel to user mode and if possible plz send some code explaining it and plz try to send me code as soon as possible bcz it is urgent. thanx again.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •