Note that there are some explanatory texts on larger screens.

plurals
  1. POCharacter processing and character iteration
    primarykey
    data
    text
    <p>Source:</p> <pre><code>#include &lt;stdio.h&gt; void main() { int i, j, tree_Size, spaces, total_Spaces, x; char tree_Characters; printf("Enter characters to use --&gt; "); scanf("%c", &amp;tree_Characters); printf("Enter size of tree --&gt; "); scanf("%d", &amp;tree_Size); //For handling top part of tree for (i = 0; i &lt;= tree_Size; i++) { printf("\n"); total_Spaces = tree_Size - i; //Determine spaces before each number for pyramid for (spaces = 1; spaces &lt;= total_Spaces; spaces++) printf(" "); //Make first line always one number for (j = -1; j &lt; i; j++) if (j &lt;= -1) printf("%c", tree_Characters); else if (j &gt; -1) printf("%c%c", tree_Characters, tree_Characters); } //For handling stem and base of tree for (i = 0; i &lt;= tree_Size; i++) { //if handling stem if (i &lt; tree_Size) { printf("\n"); for (spaces = 1; spaces &lt;= tree_Size; spaces++) printf(" "); printf("%c", tree_Characters); } //else if handling base else if (i == tree_Size) { printf("\n"); for (x = 0; x &lt;= tree_Size * 2; x++) { printf("%c", tree_Characters); } } } printf("\n"); } </code></pre> <p><a href="http://dl.dropbox.com/u/20930447/screenshots/Screenshot-9.png" rel="nofollow">Here is the output it produces so far</a><br> <a href="http://www.reddit.com/r/learnprogramming/comments/fy094/c_character_processing_and_iteration_need_help_d/" rel="nofollow">Here is a thread I made on reddit for better understanding (comments)</a> </p> <p>The goal of the assignment is for it to look like this: </p> <pre><code>*** Print a Tree *** Enter characters to use --- *|=+ Enter size of tree --- 4 * *** ***** ******* ********* | | | | ====+==== </code></pre> <p>What I don't understand is how to process characters. The teacher was mentioning putting characters into some buffer and then clearing it etc, I have no idea. Can anyone help? I have to use scanf, can't convert anything to strings or use anything advanced.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload