Program with the spaces in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BretHart
    New Member
    • Dec 2007
    • 2

    Program with the spaces in C

    Hi,
    I started to program a few months ago, but now i have a really dummy problem that i cant solve...

    So my program reads this : "asdasdas asdasdas asdasd"
    like 3 chars insted of one...

    Can anyone tell me how to put the program reading spaces like just one char?

    thkz
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    So my program reads this : "asdasdas asdasdas asdasd"
    That is a string.
    like 3 chars insted of one...
    Which means what? I don't understand what you have described. Redescribe the problem. Maybe you do not know the terminology. In that case, tell me your observations only.

    Can anyone tell me how to put the program reading spaces like just one char?
    Cannot understand the question. I'll ignore it and wait for you to redescribe the problem.

    Comment

    • BretHart
      New Member
      • Dec 2007
      • 2

      #3
      sorry, my english is very bad xDDD

      Well, the problem is:
      I have a do while, to "restart" the question when the insert value is not one that its recognize to the program, like

      Menu -> if u want to continue write 1
      If u want to do something else write 2

      The problem is when the user writes something with spaces, like "3 1312 12312"
      the program is scaning 3, 1312, 12312 like 3 diferent chars, and he is comebacking to the menu 3 times insted of one.

      Basecally i want the program to read 3 1312 12312 as one single char and not 3.

      Ex;

      Program:
      Menu -> if u want to continue write 1
      If u want to do something else write 2

      User writes 3 1312 12312

      Program:

      Menu -> if u want to continue write 1
      If u want to do something else write 2

      Menu -> if u want to continue write 1
      If u want to do something else write 2

      Menu -> if u want to continue write 1
      If u want to do something else write 2

      _____

      I want the program when the user writes something with spaces like "3 1312 12312" or "aasd 213 asda" to return only one time the menu.

      I hope that i have been clear enough

      thkz for the help

      Comment

      • primeSo
        New Member
        • Aug 2007
        • 35

        #4
        First of all, you must make it very clear between "string" and "character" in C.
        This two have distinctive differences.

        For example: "qwe qwe qwe" is a string with 3 "WORDS". Each word consists of 3 CHARACTERS. These 3 WORDS form a STRING in C. And the words is deliminated by a SPACE. THIS IS THE FUNDAMENTAL KNOWLEDGE.

        The problem you mentioned is a common buffering bug in C. I suggested you to do some reading regarding input/output(I/O) in C. You will know how to read in a space as well by studying the topic i mentioned.

        Hope this will help : )

        Comment

        Working...