<?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[Probleme mit eigener Funktion]]></title><description><![CDATA[<p>Hallo erstmal <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Ich hab da ein Problem mit ein paar Funktionen in meinem Programm. Leider kann ich nicht genau ausmachen, WO das Problem liegt.</p>
<p>Hier mal die Codezeilen für das einlesen der Highscore Datei das schreiben dieser und das verschlüsseln der Daten.</p>
<pre><code class="language-cpp">void Highscore::read()
{
	char scorepfad[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, scorepfad);
	ldatei.open(strcat (scorepfad, &quot;\\highscore.hsc&quot;), ios_base::in);

	for(int i = 0; i &lt; 10; i++)
	{
		getline(ldatei, score[i]);
		score[i] = crypt(score[i], &quot;downtimes&quot;, false);
	}

	ldatei.close();

}

string Highscore::crypt(string inp, string key, bool mode)
{
	string z, cptstring, str1;
	char c;
    unsigned int position = 0;
    int cptzahl, orgzahl, keyzahl;
    for(unsigned int i = 0; i &lt; inp.length(); i++)
    {

    	strcpy(&amp;c, (str1.assign(key, position, 1).c_str()));
        keyzahl = c;

        position++;
        if(position &gt; key.length())
        		position = 1;    

        if(mode)
        {
            //Verschlüsseln
            strcpy(&amp;c, (str1.assign(inp, i, 1).c_str()));
            orgzahl = c;
            cptzahl = orgzahl ^ keyzahl;
            ostringstream Str;
            Str &lt;&lt; cptzahl;
            cptstring = Str.str();
            if(cptstring.length() &lt; 2)
            	cptstring = &quot;0&quot; + cptstring;
            z += cptstring;
        }
        else
        {            
            //Entschlüsseln
        	cptstring.assign(inp, i, 2).c_str();
        	i++;
            cptzahl = atoi(cptstring.c_str());
            orgzahl = cptzahl ^ keyzahl;
            c = orgzahl;
            z += c;
        }
    }

    return z;

};

void Highscore::write(string name, int punkte)
{
	char scorepfad[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, scorepfad);

	string p;
	ostringstream Str;
    Str &lt;&lt; punkte;
    p = Str.str();

    while(p.length() &lt; 10)
    {
    	p += &quot; &quot;;
    }

	for(int i = 9; i &gt; pos; i--)
	{
		score[i] = score[i - 1];
	}
	score[pos] = name + p;

	sdatei.open(strcat (scorepfad, &quot;\\highscore.hsc&quot;), ios_base::out);
	for(int i = 0; i &lt; 10; i++)
	{
		score[i] = crypt(score[i], &quot;downtimes&quot;, true);
		sdatei &lt;&lt; (score[i] + &quot;\n&quot;);
	}

	sdatei.close();

	read();

};
</code></pre>
<p>Wenn ich das Programm auf meinem eignen PC in der IDE laufen lasse tut alles Einwandfrei. Schicke ich das Projekt aber nun zu einem Freund mit gleichem Betriebsystem usw und er führt es aus dann bekommt er in der Ausgabe teilweise richtige und teilweise falsche Zeichen ausgegben. Er besitzt aber die gleiche &quot;highscore.hsc&quot; Datei wie ich auch.</p>
<p>Hat einer eine Ahnung woran dieser Unterschied zwischen ihm und mir liegen könnte?</p>
<p>Vielen dank schonmal im Voraus für jegliche Hilfe</p>
<p>MFG downtimes</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/194395/probleme-mit-eigener-funktion</link><generator>RSS for Node</generator><lastBuildDate>Mon, 28 Sep 2026 11:32:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/194395.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 06 Oct 2007 11:44:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme mit eigener Funktion on Sat, 06 Oct 2007 11:44:26 GMT]]></title><description><![CDATA[<p>Hallo erstmal <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Ich hab da ein Problem mit ein paar Funktionen in meinem Programm. Leider kann ich nicht genau ausmachen, WO das Problem liegt.</p>
<p>Hier mal die Codezeilen für das einlesen der Highscore Datei das schreiben dieser und das verschlüsseln der Daten.</p>
<pre><code class="language-cpp">void Highscore::read()
{
	char scorepfad[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, scorepfad);
	ldatei.open(strcat (scorepfad, &quot;\\highscore.hsc&quot;), ios_base::in);

	for(int i = 0; i &lt; 10; i++)
	{
		getline(ldatei, score[i]);
		score[i] = crypt(score[i], &quot;downtimes&quot;, false);
	}

	ldatei.close();

}

string Highscore::crypt(string inp, string key, bool mode)
{
	string z, cptstring, str1;
	char c;
    unsigned int position = 0;
    int cptzahl, orgzahl, keyzahl;
    for(unsigned int i = 0; i &lt; inp.length(); i++)
    {

    	strcpy(&amp;c, (str1.assign(key, position, 1).c_str()));
        keyzahl = c;

        position++;
        if(position &gt; key.length())
        		position = 1;    

        if(mode)
        {
            //Verschlüsseln
            strcpy(&amp;c, (str1.assign(inp, i, 1).c_str()));
            orgzahl = c;
            cptzahl = orgzahl ^ keyzahl;
            ostringstream Str;
            Str &lt;&lt; cptzahl;
            cptstring = Str.str();
            if(cptstring.length() &lt; 2)
            	cptstring = &quot;0&quot; + cptstring;
            z += cptstring;
        }
        else
        {            
            //Entschlüsseln
        	cptstring.assign(inp, i, 2).c_str();
        	i++;
            cptzahl = atoi(cptstring.c_str());
            orgzahl = cptzahl ^ keyzahl;
            c = orgzahl;
            z += c;
        }
    }

    return z;

};

void Highscore::write(string name, int punkte)
{
	char scorepfad[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, scorepfad);

	string p;
	ostringstream Str;
    Str &lt;&lt; punkte;
    p = Str.str();

    while(p.length() &lt; 10)
    {
    	p += &quot; &quot;;
    }

	for(int i = 9; i &gt; pos; i--)
	{
		score[i] = score[i - 1];
	}
	score[pos] = name + p;

	sdatei.open(strcat (scorepfad, &quot;\\highscore.hsc&quot;), ios_base::out);
	for(int i = 0; i &lt; 10; i++)
	{
		score[i] = crypt(score[i], &quot;downtimes&quot;, true);
		sdatei &lt;&lt; (score[i] + &quot;\n&quot;);
	}

	sdatei.close();

	read();

};
</code></pre>
<p>Wenn ich das Programm auf meinem eignen PC in der IDE laufen lasse tut alles Einwandfrei. Schicke ich das Projekt aber nun zu einem Freund mit gleichem Betriebsystem usw und er führt es aus dann bekommt er in der Ausgabe teilweise richtige und teilweise falsche Zeichen ausgegben. Er besitzt aber die gleiche &quot;highscore.hsc&quot; Datei wie ich auch.</p>
<p>Hat einer eine Ahnung woran dieser Unterschied zwischen ihm und mir liegen könnte?</p>
<p>Vielen dank schonmal im Voraus für jegliche Hilfe</p>
<p>MFG downtimes</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1379075</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379075</guid><dc:creator><![CDATA[downtimes]]></dc:creator><pubDate>Sat, 06 Oct 2007 11:44:26 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit eigener Funktion on Sat, 06 Oct 2007 12:18:13 GMT]]></title><description><![CDATA[<p>Was soll die Funktion</p>
<pre><code class="language-cpp">strcpy(&amp;c, (str1.assign(key, position, 1).c_str()));
</code></pre>
<p>bewirken?<br />
Du weist einem einzelnen char einen string zu... (Speicherüberschreiber)</p>
<p>Und die Umwandlung der Zeichen in Zahlen verstehe ich auch nicht.<br />
Normalerweise wird einfach der Text zeichenweise mit dem Key verschlüsselt/entschlüsselt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1379101</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379101</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Sat, 06 Oct 2007 12:18:13 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit eigener Funktion on Sat, 06 Oct 2007 15:58:14 GMT]]></title><description><![CDATA[<p>Schien wohl wahrlich an betreffender Codezeile zu liegen.</p>
<p>Das kommt davon, wenn man sich als neuling an so sachen wagt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Danke für die Hilfe mittlerweile habich nen besseren Weg gefunden mein Problem zu realisieren</p>
<p>MFG downtimes</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1379239</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379239</guid><dc:creator><![CDATA[downtimes]]></dc:creator><pubDate>Sat, 06 Oct 2007 15:58:14 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit eigener Funktion on Sat, 06 Oct 2007 16:01:16 GMT]]></title><description><![CDATA[<p>Vielen Dank, hab das ganze jetzt komplett umgeschrieben und es funktioniert jetzt.<br />
Sieht so aus:</p>
<pre><code class="language-cpp">[code]
void Highscore::split(string source, const char* delimeter, string array[])
{
	int j = 0, k = -1;
	unsigned int i = 0;
	string str;
	i = source.find(delimeter, i + 1);
	while(i != string::npos)
	{
		array[j] = str.assign(source, k + 1, i - (k + 1));
		j++;
		k = i;
		i = source.find(delimeter, i + 1);
	}
}

void Highscore::read()
{
	char scorepfad[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, scorepfad);
	ldatei.open(strcat (scorepfad, &quot;\\highscore.hsc&quot;), ios::binary);

	ldatei.seekg(0, ios::end);
	size_t len = ldatei.tellg();
	ldatei.seekg(0, ios::beg); 

    char* buf = new char[len];
    ldatei.read(buf, len);

	ldatei.close();

	string str = crypt(buf, &quot;downtimes&quot;, false, len);

	delete[] buf;

	split(str, &quot;~&quot;, &amp;score[0]);

}

void Highscore::write(string name, int punkte)
{
	char scorepfad[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, scorepfad);

	string p;
	ostringstream Str;
	Str &lt;&lt; punkte;
	p = Str.str();

	for(int i = 19; i &gt; pos; i--)
	{
		score[i] = score[i - 2];
		i--;
		score[i] = score[i - 2];
	}

	score[pos * 2] = name;
	score[pos * 2 + 1] = p;

	string s;

	for(int i = 0; i &lt; 20; i++)
	{
		s += score[i];
		s += &quot;~&quot;;
	}

	char* buf = new char[s.size()];
	strcpy(buf, s.c_str());

	s = crypt(buf, &quot;downtimes&quot;, true, s.size());
	strcpy(buf, s.c_str());

	sdatei.open(strcat (scorepfad, &quot;\\highscore.hsc&quot;), ios::binary | ios_base::trunc);

	sdatei.write(buf, s.size());
	sdatei.close();

	delete[] buf;

};

string Highscore::crypt(char* inp, string key, bool mode, int len)
{
	string z;
	char c;
    unsigned int position = 0;
    int cptzahl, orgzahl, keyzahl;
    for(int i = 0; i &lt; len; i++)
    {

    	strcpy(&amp;c, key.substr(position, 1).c_str());
        keyzahl = c;

        position++;
        if(position &gt; key.length())
        		position = 0;    

        if(mode)
        {
            //Verschlüsseln
            orgzahl = inp[i];
            cptzahl = orgzahl ^ keyzahl;
            z += cptzahl;
        }
        else
        {   
        	//Entschlüsseln
            cptzahl = inp[i];
            orgzahl = cptzahl ^ keyzahl;
            z += orgzahl;
        }
    }
    return z;
};
[/code]
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1379242</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379242</guid><dc:creator><![CDATA[downtimes]]></dc:creator><pubDate>Sat, 06 Oct 2007 16:01:16 GMT</pubDate></item></channel></rss>