<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Häufigkeit von Wörtern in (string) Text zählen]]></title><description><![CDATA[<p>Bin Anfänger in c++ und soll ein Programm schreiben<br />
das einen Text einließt mit get.string<br />
und dann zählt wie oft ein Wort mit 1 Buchstaben , 2 Buchstaben<br />
3. Buichstaben.... vorkommt.<br />
Kann mir bitte einer helfen.<br />
Ohne s.size Funktionen etc.<br />
ganz simple soll es geschrieben sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/127879/häufigkeit-von-wörtern-in-string-text-zählen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 25 Aug 2026 06:21:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/127879.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 28 Nov 2005 13:14:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Häufigkeit von Wörtern in (string) Text zählen on Mon, 28 Nov 2005 13:14:47 GMT]]></title><description><![CDATA[<p>Bin Anfänger in c++ und soll ein Programm schreiben<br />
das einen Text einließt mit get.string<br />
und dann zählt wie oft ein Wort mit 1 Buchstaben , 2 Buchstaben<br />
3. Buichstaben.... vorkommt.<br />
Kann mir bitte einer helfen.<br />
Ohne s.size Funktionen etc.<br />
ganz simple soll es geschrieben sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/928957</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/928957</guid><dc:creator><![CDATA[PeterF.]]></dc:creator><pubDate>Mon, 28 Nov 2005 13:14:47 GMT</pubDate></item><item><title><![CDATA[Reply to Häufigkeit von Wörtern in (string) Text zählen on Mon, 28 Nov 2005 13:17:45 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=9713" rel="nofollow">estartu_de</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=1" rel="nofollow">MFC (Visual C++)</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=15" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/928962</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/928962</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Mon, 28 Nov 2005 13:17:45 GMT</pubDate></item><item><title><![CDATA[Reply to Häufigkeit von Wörtern in (string) Text zählen on Mon, 28 Nov 2005 13:26:13 GMT]]></title><description><![CDATA[<p>Wie willst du ohne size() die Länge eines Wortes bestimmen? (size ist das günstigste für diesen Zweck, du kannst natürlich dessen Funktionalität auch mit strlen oder (für die ganz hartnäckigen) einer for()-Schleife nachbauen).</p>
<p>Wenn du die Wortlänge hast, empfehle ich dir einen vector&lt;int&gt;, in dem du die Anzahlen mitschreibst:</p>
<pre><code class="language-cpp">vector&lt;int&gt; anzahl;
string wort;
while(fin&gt;&gt;wort)
{
  int char_anzahl=wort.length();//statt length() kannst du dich beliebig austoben, wenn dir das zu einfach ist
  if(char_anzahl&lt;anzahl.size())anzahl.resize(char_anzahl);
  anzahl[char_anzahl-1]++;
}
for(int n=0;n&lt;anzahl.size());++n)
  cout&lt;&lt;&quot;es gibt &quot;&lt;&lt;anzahl[n]&lt;&lt;&quot; Wörter mit &quot;&lt;&lt;n+1&lt;&lt;&quot; Buchstaben.\n&quot;;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/928966</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/928966</guid><dc:creator><![CDATA[CStoll (off)]]></dc:creator><pubDate>Mon, 28 Nov 2005 13:26:13 GMT</pubDate></item><item><title><![CDATA[Reply to Häufigkeit von Wörtern in (string) Text zählen on Mon, 28 Nov 2005 15:15:27 GMT]]></title><description><![CDATA[<p>Ja es soll wirklich für die ganz hartnäckigen programmiert werden.</p>
<p>Stelle mir ungefähr vor...<br />
Erst einmal:<br />
Char Satz[100] int Woerter[50]=0<br />
int k=1<br />
mit einer for Schleife dann<br />
einlesen wielang die verschiedenen Wörter sind<br />
bsp.<br />
for(int i=0 ; Satz[i]=&quot;\n&quot; ; i++)<br />
{<br />
if (Satz[i]=' ') int Woerter[k+1] ;<br />
else Woerter[k]=Woerter[k]+1<br />
}</p>
<p>dann haette man schonmmal in Woerter[k] die verschiedenen Längen der Woerter gespeichert aber ich brauch ja die Anzahl der verschiedenen Wörter Längen?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/929017</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/929017</guid><dc:creator><![CDATA[PeterF.]]></dc:creator><pubDate>Mon, 28 Nov 2005 15:15:27 GMT</pubDate></item><item><title><![CDATA[Reply to Häufigkeit von Wörtern in (string) Text zählen on Mon, 28 Nov 2005 17:34:39 GMT]]></title><description><![CDATA[<p>Hallo,<br />
hast du in etwa sowas gesucht?</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;

using namespace std;

int main()
{   char Satz[28] = {&quot;aaaaa bb ccc dddd dd eeeee.&quot;};
    int Woerter[28];
    for (int i = 0; i &lt; 28; i++) {
        Woerter[i] = 0; }
    int zaehler1 = 0;
    int zaehler2 = 0;
    for (int i = 0; i &lt; 28; i++)  {
         if (Satz[i]==' '||Satz[i]=='.') {
            Woerter[zaehler2-1]++;
            zaehler1++;
            zaehler2 = 0;
            }
         else {
              zaehler2++; }
    }
    for (int i = 0; i &lt; 28; i++) {
        if (Woerter[i] != 0) cout &lt;&lt; &quot;Wörter mit der Anzahl &quot; &lt;&lt; i+1 &lt;&lt; &quot;: &quot; &lt;&lt; Woerter[i] &lt;&lt; endl;
    } 
    system(&quot;PAUSE&quot;);
    return 0;
}
</code></pre>
<p>MfG Jaschi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/929117</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/929117</guid><dc:creator><![CDATA[Jaschi]]></dc:creator><pubDate>Mon, 28 Nov 2005 17:34:39 GMT</pubDate></item><item><title><![CDATA[Reply to Häufigkeit von Wörtern in (string) Text zählen on Mon, 28 Nov 2005 18:05:33 GMT]]></title><description><![CDATA[<p>Ja super genau so wollte ich es haben,<br />
jetzt nur noch eine Kleinigkeit:</p>
<p>Es soll nicht da stehen mit Wörter mit 3 Buchstaben = 2<br />
sondern Wörter mit 3 Buchstaben = ##<br />
also als Balkendiagramm mit ##</p>
]]></description><link>https://www.c-plusplus.net/forum/post/929136</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/929136</guid><dc:creator><![CDATA[PeterF.]]></dc:creator><pubDate>Mon, 28 Nov 2005 18:05:33 GMT</pubDate></item><item><title><![CDATA[Reply to Häufigkeit von Wörtern in (string) Text zählen on Mon, 28 Nov 2005 18:39:28 GMT]]></title><description><![CDATA[<p>Danke habe es selber geschafft, sieht jetzt so aus</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;

using namespace std;

int main()
{   char Satz[200];
	cout &lt;&lt; &quot;Text = ?&quot; ;
    rewind(stdin);
	cin.get(Satz, 200);

	int Woerter[200];
    for (int i = 0; i &lt; 200; i++)
	{        Woerter[i] = 0; }

	int zaehler1 = 0;

	for (int i = 0; i&lt;200 ; i++)
	{
         if (Satz[i]==' ' || Satz[i]=='\0')
		 {
            Woerter[zaehler1-1]++; 
			zaehler1 = 0;
           }
         else {
              zaehler1++; }
    }
    for (int i = 0; i &lt; 200; i++) {

		if (Woerter[i] != 0)
		{

		cout &lt;&lt; i+1 &lt;&lt; &quot;: &quot; ;
		for (int z=0; z&lt;Woerter[i]; z++)
		{			cout &lt;&lt; &quot;#&quot;;
		}
		cout &lt;&lt; endl;
            }
	}

    return 0; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/929155</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/929155</guid><dc:creator><![CDATA[PeterF.]]></dc:creator><pubDate>Mon, 28 Nov 2005 18:39:28 GMT</pubDate></item><item><title><![CDATA[Reply to Häufigkeit von Wörtern in (string) Text zählen on Mon, 28 Nov 2005 20:51:28 GMT]]></title><description><![CDATA[<p>PeterF. schrieb:</p>
<blockquote>
<p>Ja es soll wirklich für die ganz hartnäckigen programmiert werden.</p>
</blockquote>
<p>Also für die ganz harten <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> - ohne Schnick-Schnack und straight forward.<br />
Dann so:</p>
<pre><code class="language-cpp">#include &lt;map&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;iterator&gt;
#include &lt;functional&gt;
#include &lt;iomanip&gt;

typedef std::map&lt; std::string::size_type, int &gt; catalog_type;

struct Counter : std::iterator&lt; std::output_iterator_tag, void, void, void, void &gt;
{
    explicit Counter( catalog_type&amp; lz ) : m_lz( lz ) {}
    Counter&amp; operator=( catalog_type::key_type laenge ) 
    { 
        ++m_lz[laenge]; 
        return *this;
    }
    Counter&amp; operator*() { return *this; }
    Counter&amp; operator++() { return *this; }
    Counter&amp; operator++( int ) { return *this; }
private:
    catalog_type&amp; m_lz;
};
void printWL( const catalog_type::value_type&amp; lz )
{
    using namespace std;
    cout &lt;&lt; &quot;Woerter mit &quot; &lt;&lt; setw(2) &lt;&lt; static_cast&lt; unsigned &gt;( lz.first ) 
        &lt;&lt; &quot; Buchstaben = &quot;;
    const char c = cout.fill( '#' );
    cout &lt;&lt; setw( lz.second ) &lt;&lt; '#' &lt;&lt; setfill( c ) &lt;&lt; endl;
}
int main()
{
    catalog_type laengenZaehler;
    std::transform( std::istream_iterator&lt; std::string &gt;( // lesen &amp; zählen
            std::stringstream(&quot;Das ist ein langer Text mit vielen Wörtern und manches mehr&quot;) ), 
        std::istream_iterator&lt; std::string &gt;(),
        Counter( laengenZaehler ), std::mem_fun_ref( &amp;std::string::size ) );

    std::for_each( laengenZaehler.begin(), laengenZaehler.end(), &amp;printWL ); // und ausgeben
}
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f576.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--sunglasses"
      title=":sunglasses:"
      alt="🕶"
    /> .. und ohne Zwischenspeicher. Und falls Du die Wörter aus einer Datei lesen möchtest, so ersetze 'std::stringstream(&quot;..&quot;)' durch 'std::ifstream(&quot;Datei-Name&quot;)'.<br />
Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/929280</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/929280</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Mon, 28 Nov 2005 20:51:28 GMT</pubDate></item></channel></rss>