<?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[&#x5C;n]]></title><description><![CDATA[<p>#include &lt;stdio.h&gt;<br />
#include &lt;string.h&gt;<br />
void dreh(char *x);</p>
<p>int main(void)<br />
{<br />
FILE *fp1, *fp2;<br />
char quelle[40], ziel[40], a[303];<br />
printf(&quot;Quelldatei = ? &quot;);<br />
scanf(&quot;%s&quot;,quelle);<br />
printf(&quot;Zieldatei = ? &quot;);<br />
scanf(&quot;%s&quot;,ziel);</p>
<p>fp1 = fopen(quelle,&quot;r&quot;);<br />
fp2 = fopen(ziel,&quot;w&quot;);</p>
<p>if(fp1==NULL)<br />
{<br />
printf(&quot;Datei nicht gefunden\n&quot;);<br />
return(-1);<br />
}<br />
if(fp2==NULL)<br />
{<br />
printf(&quot;Fehler!\n&quot;);<br />
return(-1);<br />
}</p>
<p>fgets(a,303,fp1);</p>
<p>while(!feof(fp1))<br />
{<br />
dreh(a);<br />
fputs(a,fp2);<br />
fgets(a,303,fp1);<br />
}</p>
<p>fclose(fp1);<br />
fclose(fp2);</p>
<p>return(0);<br />
}</p>
<p>void dreh(char *x)<br />
{<br />
char *p, wert;<br />
p=x+strlen(x)-2;<br />
while(x&lt;p)<br />
{<br />
wert = *x;<br />
*x = *p;<br />
*p = wert;<br />
x++;<br />
p--;<br />
}<br />
}</p>
<p>__________________________________________</p>
<p>Ich habe bei diesem Programm ein kleines Problem, ich schrieb die funktion dreh so(liest aus textdatei, dreht jede zeile um, schreib das umgedrehte in eine andere textdatei):</p>
<p>void dreh(char *x) // dreht das Array um<br />
{<br />
char *p, wert;<br />
p=x+strlen(x)-3; //&lt;-------<br />
while(x&lt;p)<br />
{<br />
wert = *x;<br />
*x = *p;<br />
*p = wert;<br />
x++;<br />
p--;<br />
}<br />
}</p>
<p>So wie ich es in erinnerung habe besthet der Zeilenvorschub aus 2 Char Variablen, da p=x+strlen(x) auf dem \0 stehn würde müsste ich somit -3 nehmen. Funktionierte leider nicht. Kann mir jemand erklären weshalb -2 und nicht -3 richtig ist?</p>
<p>Wenn ich die bedingung habe das jede Zeile maximal aus 300 Zeichenbesteht müsste ich doch auch ein speicher Array von 303 Zeichen eröffnen (2 für \n, 1 für \0). fgets liest ja im gegensatz zu gets auch das \n ins Array ein.</p>
<p>Vielen dank!</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/120548/n</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 10:54:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/120548.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Sep 2005 11:37:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &#x5C;n on Wed, 14 Sep 2005 11:37:42 GMT]]></title><description><![CDATA[<p>#include &lt;stdio.h&gt;<br />
#include &lt;string.h&gt;<br />
void dreh(char *x);</p>
<p>int main(void)<br />
{<br />
FILE *fp1, *fp2;<br />
char quelle[40], ziel[40], a[303];<br />
printf(&quot;Quelldatei = ? &quot;);<br />
scanf(&quot;%s&quot;,quelle);<br />
printf(&quot;Zieldatei = ? &quot;);<br />
scanf(&quot;%s&quot;,ziel);</p>
<p>fp1 = fopen(quelle,&quot;r&quot;);<br />
fp2 = fopen(ziel,&quot;w&quot;);</p>
<p>if(fp1==NULL)<br />
{<br />
printf(&quot;Datei nicht gefunden\n&quot;);<br />
return(-1);<br />
}<br />
if(fp2==NULL)<br />
{<br />
printf(&quot;Fehler!\n&quot;);<br />
return(-1);<br />
}</p>
<p>fgets(a,303,fp1);</p>
<p>while(!feof(fp1))<br />
{<br />
dreh(a);<br />
fputs(a,fp2);<br />
fgets(a,303,fp1);<br />
}</p>
<p>fclose(fp1);<br />
fclose(fp2);</p>
<p>return(0);<br />
}</p>
<p>void dreh(char *x)<br />
{<br />
char *p, wert;<br />
p=x+strlen(x)-2;<br />
while(x&lt;p)<br />
{<br />
wert = *x;<br />
*x = *p;<br />
*p = wert;<br />
x++;<br />
p--;<br />
}<br />
}</p>
<p>__________________________________________</p>
<p>Ich habe bei diesem Programm ein kleines Problem, ich schrieb die funktion dreh so(liest aus textdatei, dreht jede zeile um, schreib das umgedrehte in eine andere textdatei):</p>
<p>void dreh(char *x) // dreht das Array um<br />
{<br />
char *p, wert;<br />
p=x+strlen(x)-3; //&lt;-------<br />
while(x&lt;p)<br />
{<br />
wert = *x;<br />
*x = *p;<br />
*p = wert;<br />
x++;<br />
p--;<br />
}<br />
}</p>
<p>So wie ich es in erinnerung habe besthet der Zeilenvorschub aus 2 Char Variablen, da p=x+strlen(x) auf dem \0 stehn würde müsste ich somit -3 nehmen. Funktionierte leider nicht. Kann mir jemand erklären weshalb -2 und nicht -3 richtig ist?</p>
<p>Wenn ich die bedingung habe das jede Zeile maximal aus 300 Zeichenbesteht müsste ich doch auch ein speicher Array von 303 Zeichen eröffnen (2 für \n, 1 für \0). fgets liest ja im gegensatz zu gets auch das \n ins Array ein.</p>
<p>Vielen dank!</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/871884</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/871884</guid><dc:creator><![CDATA[BLauWal]]></dc:creator><pubDate>Wed, 14 Sep 2005 11:37:42 GMT</pubDate></item><item><title><![CDATA[Reply to &#x5C;n on Wed, 14 Sep 2005 13:46:02 GMT]]></title><description><![CDATA[<p>&quot;\n&quot; ist intern EIN Zeichen, der Backslash zeigt nur dem Compiler, dass das n nicht als &quot;Text-n&quot; interpretiert werden soll, sondern als Steuerzeichen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/872047</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/872047</guid><dc:creator><![CDATA[Pellaeon]]></dc:creator><pubDate>Wed, 14 Sep 2005 13:46:02 GMT</pubDate></item></channel></rss>