<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Linux Forum &mdash; Вспоминая Си]]></title>
		<link>https://linuxforum.ru/viewtopic.php?id=24726</link>
		<atom:link href="https://linuxforum.ru/extern.php?action=feed&amp;tid=24726&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «Вспоминая Си».]]></description>
		<lastBuildDate>Tue, 16 Oct 2012 10:19:35 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Вспоминая Си]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=303813#p303813</link>
			<description><![CDATA[<p>Хотелось бы, чтобы эту тему не закрывали, т.к. наверняка в ходе прочтения книги еще наверняка возникнут вопросы, а однородные темы плодить не хочется!&nbsp; <img src="https://linuxforum.ru/img/smilies/bf.gif" alt="bf" /> <br />Спасибо!</p>]]></description>
			<author><![CDATA[null@example.com (ShooricG)]]></author>
			<pubDate>Tue, 16 Oct 2012 10:19:35 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=303813#p303813</guid>
		</item>
		<item>
			<title><![CDATA[Re: Вспоминая Си]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=303809#p303809</link>
			<description><![CDATA[<p><strong>bormant</strong>, спасибо!</p><p>Получилось примерно так:<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><p>Решение с одномерным массивом:<br /></p><div class="codebox"><pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

#define IN 1     /* in word */
#define OUT 0    /* out of word */

/* diagram of input&#039;s symbols */

main()
{
    int c, s, nw, i, j, state, max;
    int diagram[20], invertion[20];

    system(&quot;clear&quot;);

    printf(&quot;Enter text with some words\n\n&quot;);

    state = OUT;
    s = nw = j = 0;

    /* determine the number of words */

    while ((c = getchar()) != EOF) {

    /* symbol is not from word */
    if (c == &#039; &#039; || c == &#039;\n&#039; || c == &#039;\t&#039;)
        state = OUT;

    /* symbol is from word and ++word*/
    else if (state == OUT) {
        state = IN;
        ++nw;
        }

    /* number of symbols in a word */
    if (state == IN)
        ++s;

    /* if number of symbols in a word not equal 0 (more that 0)
    then j&#039;s element in array assign number of symbols in a word;
    after this for the next word number of symbols for a start
    is equal 0 and enlarge number array&#039;s element */
    else if (s != 0) {
        diagram[j] = s;
        s = 0;
        ++j;
        }
    }

    printf(&quot;\n&quot;);

    /* determine the maximum lenght of the words */

    for (j = 0; j &lt; nw; ++j)
    if (max &lt; diagram[j])
        max = diagram[j];

    /* printing vertical diagram with &#039;*&#039; and &#039; &#039; */

    for (s = max; s &gt; 0; --s) {
        for (j = 0; j &lt; nw; ++j) {
            putchar(diagram[j] &gt;= s ? &#039;*&#039; : &#039; &#039;);
        }
        putchar(&#039;\n&#039;);
    }

}</code></pre></div></div></div><p>Так же спасибо за помощь <a href="http://unixforum.org/index.php?showtopic=133214&amp;view=findpost&amp;p=1228538">NickLion</a></p>]]></description>
			<author><![CDATA[null@example.com (ShooricG)]]></author>
			<pubDate>Tue, 16 Oct 2012 10:01:26 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=303809#p303809</guid>
		</item>
		<item>
			<title><![CDATA[Re: Вспоминая Си]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=303794#p303794</link>
			<description><![CDATA[<p>Что-то вроде (только идея построения диаграммы по готовым данным):</p><div class="codebox"><pre><code>#include &lt;stdio.h&gt;

print_vd(int ncol, int* data) {
    int i, j, max;
    max=data[0];
    for (i=1; i&lt;ncol; i++) if (data[i]&gt;max) max=data[i];
    for (j=max; j&gt;0; j--) {
        for (i=0; i&lt;ncol; i++) printf(&quot; %c&quot;, data[i]&gt;=j?&#039;*&#039;:&#039; &#039;);
        printf(&quot;\n&quot;);
    }
}

int
main(void) {
    int testdata[] = {2, 3, 4, 5, 3, 7, 2};
    print_vd(sizeof(testdata)/sizeof(testdata[0]), testdata);
    return 0;
}</code></pre></div><div class="codebox"><pre><code>           *  
           *  
       *   *  
     * *   *  
   * * * * *  
 * * * * * * *
 * * * * * * *</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (bormant)]]></author>
			<pubDate>Tue, 16 Oct 2012 09:04:38 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=303794#p303794</guid>
		</item>
		<item>
			<title><![CDATA[Вспоминая Си]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=303771#p303771</link>
			<description><![CDATA[<p>Всем привет! <img src="https://linuxforum.ru/img/smilies/ab.gif" alt="ab" /> </p><p>Начну с небольшой предыстории. <img src="https://linuxforum.ru/img/smilies/bx.gif" alt="bx" /> <br />Когда-то давно (лет 5-7 назад), когда я учился на 1-2 курсе универа мы изучали язык программирования Си. С его пониманием у меня тогда проблем не возникало и практически все схватывал на лету: строки, массивы, указатели, функции - со всем был в ладах. По окончании 2 курса даже экзамен на 5 сдал. Но с тех пор прошло более 5 лет, и на &quot;Сях&quot; я больше не писал. Соответственно многое (да чего уж там таить - практически все) уже позабыто.</p><p>И вот, по истечении этих более 5 лет, я обнаруживаю, что на работе бывает появляется немного свободного времени. Чтобы даром его не терять, решил вспомнить тот самый Си. В связи с чем купил книгу &quot;Язык программирования С&quot; (Б.Керниган, Д.Ритчи; 2-е издание, &quot;Вильямс&quot;, 2012г.) и установил на рабочий комп в (к сожалению) виртуалку Debian Wheezy.<br />Начал читать книгу с интересом. И вот, на середине первой главы (1.6 Массивы) встал в ступор при выполнении упражнения.</p><p>Упражнение 1.13: Напишите программу для вывода гистограммы длин слов во входном потоке. Построить гистограмму с горизонтальными рядами довольно легко, а вот с вертикальными столбцами труднее.</p><p>Так вот, в чем трудность: горизонтальную гистограмму построить довольно-таки легко, но вот с вертикальной - ступор! :angry:&nbsp; Никак не удается ее правильно вывести на экран.</p><p>В книге 1 глава называется &quot;Вводный урок&quot; - соответственно ни о каких двумерных массивах речи не идет. Возникает вопрос - как решить данную задачу, используя только одномерный массив?</p><p>P.S.: во вложении два варианта моих мучений - 1-ый с одномерным массивом, 2-ой с двумерным массивом. Но по условию нужно дорабатывать первый вариант!</p><p>P.P.S.: заранее благодарен за любые наставления и тычиния носом! <img src="https://linuxforum.ru/img/smilies/ag.gif" alt="ag" /> </p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><p>Вариант решения с одномерным массивом:<br /></p><div class="codebox"><pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

#define IN 1     /* in word */
#define OUT 0    /* out of word */

/* diagram of input&#039;s symbols */

main()
{
    int c, s, nw, i, j, state, max;
    int diagram[20], invertion[20];

    system(&quot;clear&quot;);

    printf(&quot;Enter text with some words\n\n&quot;);

    state = OUT;
    s = nw = j = 0;

    /* determine the number of words */

    while ((c = getchar()) != EOF) {

    /* symbol is not from word */
    if (c == &#039; &#039; || c == &#039;\n&#039; || c == &#039;\t&#039;)
        state = OUT;

    /* symbol is from word and ++word*/
    else if (state == OUT) {
        state = IN;
        ++nw;
        }

    /* number of symbols in a word */
    if (state == IN)
        ++s;

    /* if number of symbols in a word not equal 0 (more that 0)
    then j&#039;s element in array assign number of symbols in a word;
    after this for the next word number of symbols for a start
    is equal 0 and enlarge number array&#039;s element */
    else if (s != 0) {
        diagram[j] = s;
        s = 0;
        ++j;
        }
    }

    printf(&quot;\n&quot;);

    /* horisontal diagram */

    for (j = 0; j &lt; nw; ++j) {
    for (s = 0; s &lt; diagram[j]; ++s)
        printf(&quot;*&quot;);
    printf(&quot;\n&quot;);
    }

    printf(&quot;\n&quot;);

    /* determine the maximum lenght of the words */

    for (j = 0; j &lt; nw; ++j)
    if (max &lt; diagram[j])
        max = diagram[j];

    /* inverting number of symbols to the vertical diagram
    with 1 and 0 */

    for (s = 0; s &lt; max; ++s) {
    invertion[s] = 0;
    for (j = 0; j &lt; nw; ++j) {
        if (diagram[j] != 0) {
        invertion[s] = ((invertion[s])*10 + 1);
        diagram[j]--;
        }
        else if (diagram[j] == 0)
        invertion[s] = (invertion[s])*10;
        }
    }

    printf(&quot;\n&quot;);

    /* printing vertical diagram with &#039;*&#039; and &#039; &#039; */

    for (s = 0; s &lt; max; ++s) {
    for (j = 0; j &lt; nw; ++j) {
        if ((invertion[s] / (10^(nw - j))) == 1)
        printf(&quot;*&quot;);
        else if (((invertion[s] / (10^(nw - j))) % 10) == 1)
        printf(&quot;*&quot;);
        else if ((invertion[s] / (10^(nw - j))) == 0)
        printf(&quot;.&quot;);
        else if (((invertion[s] / (10^(nw - j))) % 10) == 0)
        printf(&quot;.&quot;);
        }
    printf(&quot;\n&quot;);
    }

}</code></pre></div></div></div><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><p>Вариант решения с двумерным массивом:<br /></p><div class="codebox"><pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

#define IN 1     /* in the word */
#define OUT 0    /* out of the word */

/* diagram of input&#039;s symbols */

main()

{
    int nw, i, j, state, max;
    char diagram[20][20];

    system(&quot;clear&quot;);

    printf(&quot;Enter text with some words\n\n&quot;);

    state = OUT;
    nw = i = j = max = 0;

    /* determine the number of words 
    and write the words to array */

    /* nw (i) - number of words (rows);
    j - number of columns; */

    while ((i = getchar()) != EOF) {

    if (i == &#039; &#039; || i == &#039;\n&#039; || i == &#039;\t&#039;) {
        state = OUT;
        j = 0;
        }

    else if (state == OUT) {
        state = IN;
        ++nw;
        }

    if (state == IN) {
        ++j;
        if (max &lt; j)
        max = j;
        diagram[j-1][nw-1] = i;
        }

    }

    for (j = 0; j &lt; max; ++j) {
    for (i = 0; i &lt; nw; ++i)
        printf(&quot; %c &quot;, diagram[j][i]);
    printf(&quot;\n&quot;);
    }

}</code></pre></div></div></div>]]></description>
			<author><![CDATA[null@example.com (ShooricG)]]></author>
			<pubDate>Tue, 16 Oct 2012 07:31:04 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=303771#p303771</guid>
		</item>
	</channel>
</rss>
