<?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[Function Problem]]></title><description><![CDATA[<p>Hey dudes ^^,<br />
habe ne totale noob frage xD<br />
weiß irgentwie im moment voll nicht wie das geht ...</p>
<p>ich habe mehrere variablen die ich in einer header datei deklariere</p>
<p>dann eine function die die variablen ändert...</p>
<p>aber es passiert nur inerhalb der function .. was mach ich falsch? ^^</p>
<p>here code :<br />
main.cpp=</p>
<pre><code>#include &quot;functionen.h&quot;

int main(){
cout &lt;&lt; carray1 &lt;&lt; endl &lt;&lt; carray2 &lt;&lt; endl &lt;&lt; variable1 &lt;&lt; endl;
tuuttuut();
cout &lt;&lt; carray1 &lt;&lt; endl &lt;&lt; carray2 &lt;&lt; endl &lt;&lt; variable1 &lt;&lt; endl;
}
</code></pre>
<p>functionen.h=</p>
<pre><code>#include &quot;iostream.h&quot;

static char carray1[20] = &quot;Lukas&quot;;
static char carray2[10] = &quot;Monotoooo&quot;;
static unsigned int variable1 = 9999;

void tuuttuut();
</code></pre>
<p>functionen.c=</p>
<pre><code>#include &quot;functionen.h&quot;

void tuuttuut(){
carray1 = &quot;manu12&quot;
carray1 = &quot;manuuuu1231u&quot;
variable1 = 12}
</code></pre>
<p>Mfg NOOB ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/201956/function-problem</link><generator>RSS for Node</generator><lastBuildDate>Tue, 06 Oct 2026 13:06:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/201956.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 06 Jan 2008 01:57:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Function Problem on Sun, 06 Jan 2008 01:57:00 GMT]]></title><description><![CDATA[<p>Hey dudes ^^,<br />
habe ne totale noob frage xD<br />
weiß irgentwie im moment voll nicht wie das geht ...</p>
<p>ich habe mehrere variablen die ich in einer header datei deklariere</p>
<p>dann eine function die die variablen ändert...</p>
<p>aber es passiert nur inerhalb der function .. was mach ich falsch? ^^</p>
<p>here code :<br />
main.cpp=</p>
<pre><code>#include &quot;functionen.h&quot;

int main(){
cout &lt;&lt; carray1 &lt;&lt; endl &lt;&lt; carray2 &lt;&lt; endl &lt;&lt; variable1 &lt;&lt; endl;
tuuttuut();
cout &lt;&lt; carray1 &lt;&lt; endl &lt;&lt; carray2 &lt;&lt; endl &lt;&lt; variable1 &lt;&lt; endl;
}
</code></pre>
<p>functionen.h=</p>
<pre><code>#include &quot;iostream.h&quot;

static char carray1[20] = &quot;Lukas&quot;;
static char carray2[10] = &quot;Monotoooo&quot;;
static unsigned int variable1 = 9999;

void tuuttuut();
</code></pre>
<p>functionen.c=</p>
<pre><code>#include &quot;functionen.h&quot;

void tuuttuut(){
carray1 = &quot;manu12&quot;
carray1 = &quot;manuuuu1231u&quot;
variable1 = 12}
</code></pre>
<p>Mfg NOOB ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431589</guid><dc:creator><![CDATA[NOOB ^^]]></dc:creator><pubDate>Sun, 06 Jan 2008 01:57:00 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Sun, 06 Jan 2008 02:10:13 GMT]]></title><description><![CDATA[<p>das sollte gar nicht kompilieren.<br />
um zeichenketten zu kopieren, verwende die funktion strcpy (oder strncpy) aus cstring oder steige gleich auf std::string um.</p>
<p>außerdem sind die variablen, die du in der header-datei definierst static. ich nehme an, das hast du gemacht, weil es sonst nicht kompilieren würde.</p>
<p>das war aber an der falschen stelle geändert, denn durch das static bekommt jede übersetzungseinheit (das wären bei dir main.c und funktionen.c) ihre eigenen variablen carray1 und variable1 usw.</p>
<p>die lösung: im header nur deklarationen unterbringen und in einer übersetzungseinheit die definition für die variablen.<br />
das funktioniert so:</p>
<pre><code class="language-cpp">//functionen.h
extern char carray1[];
extern int variable1;
void tut();

//functionen.c
#include &quot;functionen.h&quot;
#include &lt;cstring&gt;

char carray1[] = &quot;Foo&quot;;
int variable1 = 42;

void tut ()
{
   strcpy (carray1, &quot;Bar&quot;);
   variable1 = 23;
}
</code></pre>
<p>ps: mit ein grund, warum globale variablen zu vermeiden sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431594</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431594</guid><dc:creator><![CDATA[queer_boy]]></dc:creator><pubDate>Sun, 06 Jan 2008 02:10:13 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Sun, 06 Jan 2008 02:11:07 GMT]]></title><description><![CDATA[<ol>
<li>Man kann Arrays nichts zuweisen, das dürfte so nicht durch den Compiler gehen.</li>
<li>Deine Variablen sind static, haben also interne Bindung. In main.cpp und funktionen.c gibt es also jeweils einen eigenen Satz dieser Variablen, und das ist der Grund, dass du die Änderungen in der main nicht siehst.</li>
</ol>
]]></description><link>https://www.c-plusplus.net/forum/post/1431595</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431595</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Sun, 06 Jan 2008 02:11:07 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Sun, 06 Jan 2008 02:36:11 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>In main.cpp und funktionen.c gibt es also jeweils einen eigenen Satz dieser Variablen, und das ist der Grund, dass du die Änderungen in der main nicht siehst.</p>
</blockquote>
<p>Sollte man dann static Variablen immer in .c Source-Dateien definieren und nie im Header?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431599</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431599</guid><dc:creator><![CDATA[Zwischenfrage]]></dc:creator><pubDate>Sun, 06 Jan 2008 02:36:11 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Sun, 06 Jan 2008 02:49:26 GMT]]></title><description><![CDATA[<p>static ist eine art primitiver datenkapselungsmechanismus, von daher wird wohl meistens die verwendung im header nicht das gewünschte resultat liefern. prinzipiell wäre das aber kein fehler, und wenn dir eine situation einfällt, in der du dieses verhalten brauchst...</p>
<p>(ps: dass static durch anonyme namespaces abgelöst werden soll, deutet diesen verwendungszweck ebenfalls an.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431602</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431602</guid><dc:creator><![CDATA[queer_boy]]></dc:creator><pubDate>Sun, 06 Jan 2008 02:49:26 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Sun, 06 Jan 2008 10:43:45 GMT]]></title><description><![CDATA[<p>queer_boy schrieb:</p>
<blockquote>
<p>wenn dir eine situation einfällt, in der du dieses verhalten brauchst...</p>
</blockquote>
<p><a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Nifty_Counter" rel="nofollow">http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Nifty_Counter</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431673</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Sun, 06 Jan 2008 10:43:45 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Sun, 06 Jan 2008 10:56:47 GMT]]></title><description><![CDATA[<p>für strings in c++ std::string und nicht char*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431676</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431676</guid><dc:creator><![CDATA[und wieder mal]]></dc:creator><pubDate>Sun, 06 Jan 2008 10:56:47 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Sun, 06 Jan 2008 13:11:27 GMT]]></title><description><![CDATA[<p>Also static Variablen gelten, wenn man sie in dem Modul als global deklariert, nur in diesem Modul, obwohl sie global deklariert sind? Und wenn man in einer Funktion eine Variable static deklariert, dann ist sie zwar lokal, wird aber, wenn man die Funktion verlässt, nicht zerstört, behält also quasi ihren Speicherbereich noch?</p>
<p>Ist das das Einzige was static bringt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431755</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431755</guid><dc:creator><![CDATA[Culfa]]></dc:creator><pubDate>Sun, 06 Jan 2008 13:11:27 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Sun, 06 Jan 2008 13:19:59 GMT]]></title><description><![CDATA[<p>schließlich gibt es noch statische klassenvariablen/funktionen, die dann für alle instanzen dieselben sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431762</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431762</guid><dc:creator><![CDATA[queer_boy]]></dc:creator><pubDate>Sun, 06 Jan 2008 13:19:59 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Sun, 06 Jan 2008 13:56:51 GMT]]></title><description><![CDATA[<p>kk habe ja gesagt noob frage <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /><br />
schon lange nicht mehr programmiert..</p>
<p>naja jetzt dann ne frage:</p>
<p>also wie soll ich das machen ..</p>
<p>ich möchte eine function die mit</p>
<pre><code>DWORD WINAPI GetPrivateProfileString(
  __in   LPCTSTR lpAppName,
  __in   LPCTSTR lpKeyName,
  __in   LPCTSTR lpDefault,
  __out  LPTSTR lpReturnedString,
  __in   DWORD nSize,
  __in   LPCTSTR lpFileName
);
</code></pre>
<p>daten aus einer ini datei ließt</p>
<p>habe in main.cpp<br />
nur den aufruf der funktion laden und dann gibt der das aus also</p>
<pre><code>#include &quot;windows.h&quot;
#include &quot;function.h&quot;
...
...
...
lesedateiaus();
cout &lt;&lt; blabla1[] &lt;&lt; testtaa[] &lt;&lt; muuuuh[];
...
...
...
</code></pre>
<p>ind function.h habe ich die arrays deklariert(und die function halt)</p>
<pre><code>#include &lt;iostream&gt;

extern char blablal[20]; //muss ne größe angeben für function später
extern char testtaa[20];
extern char muuuuh[20];

void lesedateiaus();
</code></pre>
<p>dann in function.c die funktion halt.</p>
<pre><code>#include &quot;windows.h&quot;
#include &quot;function.h&quot;

lesedateiaus(){
GetPrivateProfileString(&quot;test&quot;,&quot;array1&quot;,&quot;Error&quot;,blablal,sizeof(blablal),&quot;C:\\test.ini&quot;);
//das dann noch für die anderen arrays
GetPrivateProfileString(&quot;test&quot;,&quot;array2&quot;,&quot;Error&quot;,testtaa,sizeof(testtaa),&quot;C:\\test.ini&quot;);
GetPrivateProfileString(&quot;test&quot;,&quot;array2&quot;,&quot;Error&quot;,muuuuh,sizeof(muuuuh),&quot;C:\\test.ini&quot;);
}
</code></pre>
<p>also das ist jetzt falsch...<br />
aber wie könnte ich es &quot;&quot;&quot;professionell&quot;&quot;&quot; lösen?^^</p>
<p>Mfg NOOB ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431794</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431794</guid><dc:creator><![CDATA[NOOB ^^]]></dc:creator><pubDate>Sun, 06 Jan 2008 13:56:51 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Mon, 07 Jan 2008 21:16:50 GMT]]></title><description><![CDATA[<p>weiß das keiner? o.o</p>
<p>ka wie ich das machen soll</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1432722</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1432722</guid><dc:creator><![CDATA[NOOB ^^]]></dc:creator><pubDate>Mon, 07 Jan 2008 21:16:50 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Tue, 08 Jan 2008 11:43:36 GMT]]></title><description><![CDATA[<p>Was funktioniert denn nicht (Compilerfehler, Laufzeitfehler, falsche Rückgabewerte)?</p>
<p>P.S. Dies ist dann eher eine Frage für das WinAPI-Forum...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1432946</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1432946</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Tue, 08 Jan 2008 11:43:36 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Tue, 08 Jan 2008 14:02:51 GMT]]></title><description><![CDATA[<p>da kommt das ich die variable nicht deklariert habe ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1433038</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1433038</guid><dc:creator><![CDATA[NOOB ^^]]></dc:creator><pubDate>Tue, 08 Jan 2008 14:02:51 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Tue, 08 Jan 2008 14:09:47 GMT]]></title><description><![CDATA[<p>Dann deklariere sie doch, wo ist da das Problem?</p>
<p>btw, wenn sich der Linker beschwert, liegt es vermutlich an einer fehlenden <strong>Definition</strong> - dem reicht der extern-Eintrag im Header nämlich nicht aus. Da mußt du am Anfang der &quot;funktion.c&quot; noch die Definitionen ergänzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1433044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1433044</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 08 Jan 2008 14:09:47 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Tue, 08 Jan 2008 21:36:38 GMT]]></title><description><![CDATA[<p>bekomme jetzt ganz oft so einen error :</p>
<pre><code>[Linker error] undefined reference to `variablen_name'
</code></pre>
<p>also füre jede variable 2-3 mal<br />
denke ma pro aufruf oder so.</p>
<p>Mfg NOOB ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1433319</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1433319</guid><dc:creator><![CDATA[NOOB ^^]]></dc:creator><pubDate>Tue, 08 Jan 2008 21:36:38 GMT</pubDate></item><item><title><![CDATA[Reply to Function Problem on Tue, 08 Jan 2008 21:40:05 GMT]]></title><description><![CDATA[<p>omg geschaft ^^ sry xD<br />
mega noob einfach zu faul gewesen sorry</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1433320</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1433320</guid><dc:creator><![CDATA[NOOB ^^]]></dc:creator><pubDate>Tue, 08 Jan 2008 21:40:05 GMT</pubDate></item></channel></rss>