Programming Challenges - Page 18


Page 18 of 19 FirstFirst ... 8141516171819 LastLast
Results 256 to 270 of 279

Thread: Programming Challenges

  1. #256
    Join Date
    Feb 2004
    Location
    Singapore
    Posts
    2,171
    Code:
    # echo "abc" | sed s/abc/`echo "123"`/
    123
    This shows that you can simply use
    Code:
    i=string
    sed s/somestring/`echo $i`/
    EDIT:: be careful of the ` ' and " ! They are all different and you need to terminate each opening with a closing of the same type! ' and " can be used interchangeably, while ` is the one that really causes things to be interpreted by the shell. It (the executing `) is usually above the tab button.
    Last edited by XiaoKJ; 01-07-2007 at 11:45 AM.
    Come under the reign of the Idiot King...
    Come to me ... I love linux!

    Registered Linux user: Idiot King #350544

  2. #257
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,947
    Hey, look, another Useless Use Of Backticks! Forget the backticks (especially when all they do is call echo), just use the value directly.

    In this case, the problem seems to be that when you put sed's argument in single quotes, which is the "standard" way to run sed, the shell doesn't interpret any special characters. (This is why it's the "standard" way to run sed; some of the shell special characters need to be left alone by the shell, so that sed can interpret them.) That includes the $ character, which starts a variable reference; if you use $abc inside single quotes, you'll get $abc out, not the value of the shell variable abc.

    So a better fix would be to run sed like this:

    i=string
    sed -e "s/some string/$i/"

    (I left the double quotes in so that you could use whitespace in either the match or the replacement. Either way, you'll have to replace any $ characters in both the match and the replacement if you don't want the shell to replace them with a variable's value, but without the double quotes, you'd have to escape spaces, tabs, and newlines also.)

  3. #258
    Join Date
    Apr 2007
    Posts
    4

    Game Challenge

    Can someone do a simple client-server game for Linux using FIFO? It's about being simple when it comes to code...I mean C++ code.

  4. #259
    Join Date
    Apr 2007
    Posts
    4

    Shell

    Who can do a primitive Linux shell? This will have to get a command from the command prompt,solve it than after it finishes,comes back and waits for an other command.

  5. #260
    Join Date
    Apr 2007
    Posts
    4

    Code correction

    When i compile this code with gcc i get the error message "Segmentation fault" . Can anyone correct the code please?
    Attached Files Attached Files

  6. #261
    Join Date
    Sep 2003
    Location
    Rochester, MN
    Posts
    3,607
    hartson: I'm not sure those are exactly the kind of programming challenges that were intended. Most of them so far have been relatively small with only a few lines of code. Neither of yours are going to fall under that category.

    Incidentally I've done both in my senior project from school that I'm still occasionally adding to. It's a client-server game with a console that acts like a Linux shell (albeit an extremely simple one). I would post the code, but it's neither complete nor fit for third party consumption, and it's about 4500 lines as it stands right now.

  7. #262
    Join Date
    Sep 2005
    Posts
    681
    trying to learn C++ it totally sucks...... i need to write a blackjack program and well im having to many problems with stupid syntax ........ I like web programming (php , )
    "Software is like sex: it's better when its free."
    -LINUS TORVALDS

  8. #263
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    cybertron is right. A good challenge is probably about 100-20 lines of code or less.

    Here is a common problem:
    Write a program that takes an unsigned integer, and outputs it in binary form.
    Last edited by Sepero; 05-02-2007 at 09:53 PM.

  9. #264
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    What format is the decimal being taken in as? Decimal, hex?
    if (i_forgot && this_is_about_code)
    language = c++;

  10. #265
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Guess it doesn't really matter. C++ attached.
    Attached Files Attached Files
    if (i_forgot && this_is_about_code)
    language = c++;

  11. #266
    Join Date
    Sep 2005
    Posts
    681
    c++ suxs in my opinion...... way to fussy and not for me.... ill stick to web programming php///// using mysql / etc ..........
    "Software is like sex: it's better when its free."
    -LINUS TORVALDS

  12. #267
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    tecknophreak saves the day again.

  13. #268
    Join Date
    May 2007
    Posts
    59
    Quote Originally Posted by crow2icedearth
    ill stick to web programming
    What happens when you need to make something that is impossible with php?
    If C++ isn't for you, then try python, java etc etc... there are just too many languages to swear off programming without trying them.

    right now im *attempting* to create some sort of mud client in python, what i have is a main function that gives a desciption and asks for an input, and in it there's an if/elif/else statement that calls other functions based on the input.
    At the end of each function, the main descript one will be called.
    - Ryan "Boxxertrumps" Trumpa

  14. #269
    Join Date
    Sep 2005
    Posts
    681
    i just dont like c++ much so far. i might if i get good at it........ who knows
    "Software is like sex: it's better when its free."
    -LINUS TORVALDS

  15. #270
    Join Date
    Sep 2003
    Location
    Rochester, MN
    Posts
    3,607
    C++ is not easy, but it gives you a lot of power once you get to know it (sometimes too much).

    boxxertrumps: Are you saying that the main function is going to call individual functions that will then call the main function again? If so, eventually you're going to exhaust your stack space and your app will crash. Just let the functions return normally and add a loop to the main function. Of course if that's not what you're planning to do then never mind.

Posting Permissions

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