<?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[dringende Hilfe bei Libaray und return gebraucht]]></title><description><![CDATA[<p>hier erstmal meine Code:</p>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string&gt;
#include&lt;iostream&gt;
#include&lt;fcntl.h&gt;
#include&lt;sys/stat.h&gt;
#include&lt;fstream&gt;
#include&lt;vector&gt;

using namespace std;

class kontaktlist
{
public:
ifstream is;
ofstream off;

	kontaktlist(char* begin,char *neu) {
 		readlist(begin);
   		writelist(begin,neu);
  		clearlist(begin,neu);
	}

	void readlist (char *begin){
	        string end=&quot;.c&quot;;
	        string all = begin + end;
	  	char *next_r = &amp;all.at(0);
		is.open(next_r,ios::in);
		  if (is.is_open())
		  {
			is.seekg (0, ios::end);
  		  	int length_r = 0;
		  	length_r = is.tellg();
  		  	is.seekg (0, ios::beg);
		  	char *buffer_r = new char[length_r];
			char foo_r[length_r];
		  	is.read (buffer_r,length_r);
		  	is.close();
			memcpy(foo_r,buffer_r,length_r);
			return (foo_r);
		  	}else{
			is.close();
			off.open(next_r,ios::out|ios::app);
			off&lt;&lt;&quot;&quot;;
			off.close();
			return NULL;
		}
	}

	void writelist (char *begin,string neu){
		string end=&quot;.c&quot;;
	        string all = begin + end;
	  	char *next_w = &amp;all.at(0);
	    	is.open(next_w,ios::in);
		if (is.is_open())
  		{
			is.close();
			off.open(next_w,ios::out|ios::app);
    			neu= neu + ';';
		    	char *neu_w = &amp;neu.at(0);
			off&lt;&lt;neu_w;
    			off.close();
  		}else{
			is.close();
			off.open(next_w,ios::out|ios::app);
			off&lt;&lt;&quot;&quot;;
			off.close();
		}
	}

	void clearlist(char *begin_c,char *name){
		int i=0;
		int anz=0;
		string end_c =&quot;.c&quot;;
		string all_c = begin_c + end_c;
		char *next_c = &amp;all_c.at(0);
		is.open(next_c,ios::in);
		if(is.is_open()){
			is.seekg (0, ios::end);
  			int length_c = 0;
			length_c = is.tellg();
			char vor[length_c];
  			is.seekg (0, ios::beg);
			//Abfangschleife:Datei ist leer
			if(length_c==0)
			{
				is.close();
			}else{
				char *buffer_c = new char[length_c];
				is.read (buffer_c,length_c);
				memcpy(vor,buffer_c,length_c);
				for(int k= 0;k&lt;length_c;k++)
				{
					if(vor[k]==';')
					{
						anz++;
					}
				}
				string foo_c[anz];
				for(int h= 0;h&lt;length_c-1;h++)
				{
					if(vor[h]==';')
					{
						i++;
					}else{
						foo_c[i] +=vor[h];
					}

			 	}
				bool kontr= false;
				for(int j=0;j&lt;i;j++)
				{
				  	if(foo_c[j]== name)
					{
						for (int l=j; l&lt;i;l++)
				    		{
							foo_c[l]=foo_c[l+1];
						}
					kontr=true;	
					}
				}
				//Kontrallschleife: eigegebener Benutzer existiert nicht in der Kontaktliste
				if(kontr== false)
				{
					is.close();
				}else{
				 	is.close();
				 	off.open(next_c,ios::out);
				 	for(int l= 0;l&lt;i-1;l++)
					{
				 		off&lt;&lt;foo_c[l];
						off&lt;&lt;';';
				 	}
				 	off.close();
				}
			}
		}else{
			//Datei existiert nicht und wirde deshalb erzeugt
			is.close();
			off.open(next_c,ios::out|ios::app);
			off&lt;&lt;&quot;&quot;;
			off.close();		
		}
	}

};
 int main(){
    kontaktlist test(&quot;cat&quot;,&quot;hallo&quot;);
    return 0;
 }
</code></pre>
<p>Nun in readlist wird eine Datei geöffnet.<br />
Nun soll der Inhalt der Datei in einem Array returnt werden.<br />
Wenn die Datei leer ist soll ein leeares Array returnt werden (mgl. dynamisch also vector)<br />
beim Kompilken gibt gcc mir folgendes zurück:</p>
<p>Dante@linux:~/Programme/CPP&gt; g++ -o realclearkontaktlist realclearkontaktlist.cpp<br />
realclearkontaktlist.cpp: In member function ‘void kontaktlist::readlist(char*)’:<br />
realclearkontaktlist.cpp:41: error: return-statement with a value, in function returning 'void'<br />
realclearkontaktlist.cpp:47: error: return-statement with a value, in function returning 'void'<br />
Dante@linux:~/Programme/CPP&gt;</p>
<p>1. Woran liegt das und wie kann man das Problem beheben??<br />
2. Wie wandelt man das Programm in eine Libary um? (bitte ausführlich, habe sowas noch nie gemacht, geschweige denn die Libaraies verstanden)</p>
<p>pls helped me.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/137042/dringende-hilfe-bei-libaray-und-return-gebraucht</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 16:48:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/137042.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 14 Feb 2006 21:50:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to dringende Hilfe bei Libaray und return gebraucht on Tue, 14 Feb 2006 21:50:01 GMT]]></title><description><![CDATA[<p>hier erstmal meine Code:</p>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string&gt;
#include&lt;iostream&gt;
#include&lt;fcntl.h&gt;
#include&lt;sys/stat.h&gt;
#include&lt;fstream&gt;
#include&lt;vector&gt;

using namespace std;

class kontaktlist
{
public:
ifstream is;
ofstream off;

	kontaktlist(char* begin,char *neu) {
 		readlist(begin);
   		writelist(begin,neu);
  		clearlist(begin,neu);
	}

	void readlist (char *begin){
	        string end=&quot;.c&quot;;
	        string all = begin + end;
	  	char *next_r = &amp;all.at(0);
		is.open(next_r,ios::in);
		  if (is.is_open())
		  {
			is.seekg (0, ios::end);
  		  	int length_r = 0;
		  	length_r = is.tellg();
  		  	is.seekg (0, ios::beg);
		  	char *buffer_r = new char[length_r];
			char foo_r[length_r];
		  	is.read (buffer_r,length_r);
		  	is.close();
			memcpy(foo_r,buffer_r,length_r);
			return (foo_r);
		  	}else{
			is.close();
			off.open(next_r,ios::out|ios::app);
			off&lt;&lt;&quot;&quot;;
			off.close();
			return NULL;
		}
	}

	void writelist (char *begin,string neu){
		string end=&quot;.c&quot;;
	        string all = begin + end;
	  	char *next_w = &amp;all.at(0);
	    	is.open(next_w,ios::in);
		if (is.is_open())
  		{
			is.close();
			off.open(next_w,ios::out|ios::app);
    			neu= neu + ';';
		    	char *neu_w = &amp;neu.at(0);
			off&lt;&lt;neu_w;
    			off.close();
  		}else{
			is.close();
			off.open(next_w,ios::out|ios::app);
			off&lt;&lt;&quot;&quot;;
			off.close();
		}
	}

	void clearlist(char *begin_c,char *name){
		int i=0;
		int anz=0;
		string end_c =&quot;.c&quot;;
		string all_c = begin_c + end_c;
		char *next_c = &amp;all_c.at(0);
		is.open(next_c,ios::in);
		if(is.is_open()){
			is.seekg (0, ios::end);
  			int length_c = 0;
			length_c = is.tellg();
			char vor[length_c];
  			is.seekg (0, ios::beg);
			//Abfangschleife:Datei ist leer
			if(length_c==0)
			{
				is.close();
			}else{
				char *buffer_c = new char[length_c];
				is.read (buffer_c,length_c);
				memcpy(vor,buffer_c,length_c);
				for(int k= 0;k&lt;length_c;k++)
				{
					if(vor[k]==';')
					{
						anz++;
					}
				}
				string foo_c[anz];
				for(int h= 0;h&lt;length_c-1;h++)
				{
					if(vor[h]==';')
					{
						i++;
					}else{
						foo_c[i] +=vor[h];
					}

			 	}
				bool kontr= false;
				for(int j=0;j&lt;i;j++)
				{
				  	if(foo_c[j]== name)
					{
						for (int l=j; l&lt;i;l++)
				    		{
							foo_c[l]=foo_c[l+1];
						}
					kontr=true;	
					}
				}
				//Kontrallschleife: eigegebener Benutzer existiert nicht in der Kontaktliste
				if(kontr== false)
				{
					is.close();
				}else{
				 	is.close();
				 	off.open(next_c,ios::out);
				 	for(int l= 0;l&lt;i-1;l++)
					{
				 		off&lt;&lt;foo_c[l];
						off&lt;&lt;';';
				 	}
				 	off.close();
				}
			}
		}else{
			//Datei existiert nicht und wirde deshalb erzeugt
			is.close();
			off.open(next_c,ios::out|ios::app);
			off&lt;&lt;&quot;&quot;;
			off.close();		
		}
	}

};
 int main(){
    kontaktlist test(&quot;cat&quot;,&quot;hallo&quot;);
    return 0;
 }
</code></pre>
<p>Nun in readlist wird eine Datei geöffnet.<br />
Nun soll der Inhalt der Datei in einem Array returnt werden.<br />
Wenn die Datei leer ist soll ein leeares Array returnt werden (mgl. dynamisch also vector)<br />
beim Kompilken gibt gcc mir folgendes zurück:</p>
<p>Dante@linux:~/Programme/CPP&gt; g++ -o realclearkontaktlist realclearkontaktlist.cpp<br />
realclearkontaktlist.cpp: In member function ‘void kontaktlist::readlist(char*)’:<br />
realclearkontaktlist.cpp:41: error: return-statement with a value, in function returning 'void'<br />
realclearkontaktlist.cpp:47: error: return-statement with a value, in function returning 'void'<br />
Dante@linux:~/Programme/CPP&gt;</p>
<p>1. Woran liegt das und wie kann man das Problem beheben??<br />
2. Wie wandelt man das Programm in eine Libary um? (bitte ausführlich, habe sowas noch nie gemacht, geschweige denn die Libaraies verstanden)</p>
<p>pls helped me.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/994406</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/994406</guid><dc:creator><![CDATA[Dante McRayne]]></dc:creator><pubDate>Tue, 14 Feb 2006 21:50:01 GMT</pubDate></item><item><title><![CDATA[Reply to dringende Hilfe bei Libaray und return gebraucht on Wed, 15 Feb 2006 07:42:24 GMT]]></title><description><![CDATA[<p>Wenn du einen Wert zurückgeben willst, darfst du die Funktion nicht &quot;void&quot; deklarieren, sondern mit dem gewünschten Rückgabetyp:</p>
<pre><code class="language-cpp">vector&lt;string&gt; readlist(const string&amp; name);
</code></pre>
<p>(btw, Pointer auf lokale Variablen (foo_r) solltest du sowieso nicht zurückgeben und den richtigen Umgang mit string's mußt du auch noch üben ;))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/994488</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/994488</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 15 Feb 2006 07:42:24 GMT</pubDate></item><item><title><![CDATA[Reply to dringende Hilfe bei Libaray und return gebraucht on Wed, 15 Feb 2006 11:08:33 GMT]]></title><description><![CDATA[<p>Ok danke ich schreibs um, aberwie mache ich daraus ne Bibliothek??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/994673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/994673</guid><dc:creator><![CDATA[Dante McRayne]]></dc:creator><pubDate>Wed, 15 Feb 2006 11:08:33 GMT</pubDate></item></channel></rss>