How to format output to look like barcode

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 123scope
    New Member
    • Mar 2010
    • 12

    How to format output to look like barcode

    hey readers, can you please tell me how to write a c program which looks something like this.

    ./task.c
    part 1Enter barcode (input): 9300605048577

    part 2 prints:- Barcode is 930-060504-857-7

    i know how to do part 1 but i need help with part 2. how can i make the inputed barcode print like shown above in part 2.
    thx
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    what controls the position of the - operator?

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      Convert your example input into your example output with pencil and paper. How did you do it?

      Comment

      • 123scope
        New Member
        • Mar 2010
        • 12

        #4
        i am talking about doing this in C complier. i cant use any strings etc. its just integers.

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

          #5
          What donbock really means is: Give us the algorithm. We don't know about the format of your barcode so we're liable to come up with something like:
          9-30060504857-7 or
          9300-6050-4857-7 or
          9300-60504-8577

          You're going to have problems, if you can't use strings. The maximum value most compliers take for an int is 4294967296, which is significantly smaller.

          I suggest you either read it character by character, or as a string line.

          Comment

          • donbock
            Recognized Expert Top Contributor
            • Mar 2008
            • 2427

            #6
            I would like you to try this with pencil and paper for a few cases. Doing so should make the necessary algorithm obvious. Then you can write your C code.

            Comment

            • 123scope
              New Member
              • Mar 2010
              • 12

              #7
              ok i did it on paper, but i think i have a problem typing the right commands.
              and buy the way i can use long integer to input and processes longer numbers.
              i prefer to use basic operators while writing this program, cant use string, arrays or functions.

              Comment

              • jkmyoung
                Recognized Expert Top Contributor
                • Mar 2006
                • 2057

                #8
                Is it possible for you to type out the work? Help us, help you.

                You probably need a modulus operator. %

                Eg. Take long num = 123456,
                To get 12:
                num / 10000;
                To get 3:
                (num / 1000) % 10;
                To get 45:
                (num /10) % 100;

                Comment

                Working...