Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

thinkpad20 Group Title

Help with entering a string that includes spaces in C++. I'm doing the first problem of problem set 1 for Stanford CS106B. The goal is to remove all instances of a target string from a source string and return the source. Here's the code I have: http://pastebin.com/4YuNADaa It works for all "solid" strings but crashes when I put something in with spaces. Any help?

  • 2 years ago
  • 2 years ago

  • This Question is Open
  1. shahzadjalbani Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Yes you must write gets(variable); to input spaces as well .

    • 2 years ago
  2. thinkpad20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I don't understand what you mean. Is gets a function? Perhaps you could show me with code.

    • 2 years ago
  3. shahzadjalbani Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    I want to say this: #include<iostream.h> #inlcude<conio.h> #inlucde<conio.h> int main() { char name[20]; gets(name); cout<<"\n"<<name; return 0; getch(); }

    • 2 years ago
  4. thinkpad20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Hmm, so we're using the char type... any reason for that? Can I use the same find functions, etc for a char that I can for a string? Or might I be able to convert the char to a string? I'm new to C++.

    • 2 years ago
  5. shahzadjalbani Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Yes you can use this to string as well.

    • 2 years ago
  6. thinkpad20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    OK, I used the string() function and it seems I'm done! Thanks a bunch! Seems like an unnecessary step... but I'm used to Python, hehe. I'm sure this way has its reasons/advantages. Anyway, thanks again.

    • 2 years ago
  7. thinkpad20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ^ I mean to say I combined what you suggested to get the character input and then put that in the string function to convert to a string ;)

    • 2 years ago
  8. shahzadjalbani Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    I need your help in python.

    • 2 years ago
  9. bmp Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Only avoid using gets(). Such a bad function for generic I/O. Use fgets() instead. Read more about it here: http://www.gidnetwork.com/b-56.html

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.