how can I write a given SENTENCE in triangle ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xhani
    New Member
    • Nov 2009
    • 2

    #1

    how can I write a given SENTENCE in triangle ?

    Hi , can anyone help me about writing a given sentence in Floyd's triangle .

    e.g ,

    printf("Write a sentence:\n");

    sentence=getcha r(); ( I should not use arrays , functions,point ers)


    and as a sentence this one is given , e.g. helloworld!

    W
    WW
    WWW
    WWWW
    WWWWW
    WWWWWW
    WW+++++++

    and if the triangle is not filled with letters of the sentence, it should be filled with + .


    IS ANYONE THAT CAN HELP ME ABOUT THAT ...
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You're going to have to explain the question a little more as I didn't understand one bit of it.

    Comment

    • xhani
      New Member
      • Nov 2009
      • 2

      #3
      Using of arrays,pointers ,functions is forbidden

      In this code I should take from user a SENTENCE and save it in a Char Variable.
      User after writing the sentence can type '#' to end the input. After the user enters the sentence,it can be with (commas ',' duts'.' and space' ' ) .Then I should do the functions for counting how many words, how many sentences... I've done whole the code. Just one part is missing. Writing that given sentence in FLOYD's triangle.

      printf("Type a sentence,to end type #:\n");
      sentence=getcha r();

      while (sentence!='#') {
      /*I did the functions for counting words,sentences ,then just
      the printing part of FLOYD's triangle shape of sentence is missing

      **** if we think that user writes this sentence ,"Hello,toda y Im gonna solve it.#"

      the triangle should be like this ..

      h
      el
      lo,
      toda
      yImgo
      nnasol
      veit.++ And if the Triangle shape is not correct, to be well-shaped the
      the missing part should be filled with '+'

      :)

      Comment

      • spiralfire
        New Member
        • Nov 2009
        • 8

        #4
        Originally posted by xhani
        Using of arrays,pointers ,functions is forbidden

        In this code I should take from user a SENTENCE and save it in a Char Variable.
        User after writing the sentence can type '#' to end the input. After the user enters the sentence,it can be with (commas ',' duts'.' and space' ' ) .Then I should do the functions for counting how many words, how many sentences... I've done whole the code. Just one part is missing. Writing that given sentence in FLOYD's triangle.

        printf("Type a sentence,to end type #:\n");
        sentence=getcha r();

        while (sentence!='#') {
        /*I did the functions for counting words,sentences ,then just
        the printing part of FLOYD's triangle shape of sentence is missing

        **** if we think that user writes this sentence ,"Hello,toda y Im gonna solve it.#"

        the triangle should be like this ..

        h
        el
        lo,
        toda
        yImgo
        nnasol
        veit.++ And if the Triangle shape is not correct, to be well-shaped the
        the missing part should be filled with '+'

        :)
        write a loop, and keep an int, starting on "1". this will be the number of chars you will be printing, and an int that keeps the amount of chars you already printed.

        so:
        Code:
        while( bool value )
           the for here (numbers of chars to print on current line)
              print one char
              increment amount of chars printed
              if you have printed all chars from the sentence
                 loop here to print the '+' you need.
                 break from the inner loop (for) and outter loop (while) setting the while condition to false, so it won't loop anymore
        end
        i think this will solve it, now write some c code!

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Actually I think its impossible using C standard library functions.

          How will you store the sentence if not in an array (which are forbidden)?

          You can't take direct input because all C standard library functions echo the data input and that would muck up your formatting.

          Actually while typing that sentence I thought of the solution. It involves taking advantage of the input character echo and just outputting newline characters at the relevant times (character positions). Then at the end of the sentence (the '.') outputting the correct number of '+'.

          spiralfire your solution will not work because although you have print char I assume you mean character of the sentence but to do this you must specifically not print any characters of the sentence and also you never print any newlines which are the one thing (apart from possibly '+') that you must print.

          Comment

          Working...