<?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[fscanf trennt : nicht]]></title><description><![CDATA[<p>guten abend,</p>
<p>in meinem code trennt fscanf mein : nicht.<br />
was mach ich da falsch?</p>
<pre><code class="language-cpp">// 
// File:   pwdsort.cc
// Author: xmo
//
// Created on 5. Mai 2008, 12:31
//

#include &lt;stdlib.h&gt;
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;string&gt;
#include &lt;sys/stat.h&gt;
using namespace std;
//
// 
//
string sortOption = &quot;name&quot;;
string path = &quot;/etc/password&quot;;
string newPath;
string synkom = &quot;pwdsort&quot;;
string myCin;
size_t found;
FILE * pFile;
char buffer [130];

struct pwdent {
char name[10];
char pwd[10];
int uid;
int gid;
char gcos[40];
char home[40];
char shell[20];
};
pwdent structs[100];

void checkKommando(string input)
{
  if(input.substr(0,synkom.length()) == synkom)
  {
      if(input.find(&quot; -&quot;) != string::npos)
      {         
          sortOption = input.substr(synkom.length()+2, 4); //4 muss ersetzt werden
          cout &lt;&lt; sortOption &lt;&lt; '\n'; //Testweise
      }

      if(input.rfind(&quot; &quot;) != string::npos &amp;&amp; (input.rfind(&quot; &quot;) + 1) != input.rfind(&quot;-&quot;))
      {
          path = input.substr(input.rfind(&quot; &quot;) + 1, input.length() - input.rfind(&quot; &quot;));
          cout &lt;&lt; path &lt;&lt; '\n'; //Testweise
      }

  }else cerr &lt;&lt; &quot;Syntax fehler&quot;;
}

// HIER IN DIESER FUNKTION IST DAS PROBLEM

void readFile()
{
   char* myPath = const_cast&lt;char*&gt;(path.c_str());
   pFile = fopen (myPath , &quot;r&quot;);
   if (pFile != NULL)
    {
       for(int i = 0 ; i &lt; !feof(pFile)&amp;&amp; i &lt; 1000 ; i++)
       {
        fscanf(pFile,&quot;%s:%s:%d:%d:%s:%s:%s\n&quot;,structs[i].name,structs[i].pwd,structs[i].uid,structs[i].gid,structs[i].gcos,structs[i].home,structs[i].shell);
       }
       fclose (pFile);
   }else cerr &lt;&lt; &quot;Pfad nicht gefunden&quot;;

  printf(&quot;%s#%s#%d#%d#%s#%s#%s&quot;,structs[0].name,structs[0].pwd,structs[0].uid,structs[0].gid,structs[0].gcos,structs[0].home,structs[0].shell);
}

int main(int argc, char** argv) {

    getline(cin, myCin);
    checkKommando(myCin);
    readFile();

    return (EXIT_SUCCESS);
}
</code></pre>
<p>die txt datei sie ungefähr so aus:<br />
name1:paswort1:1:1....<br />
name1:passwort2:2:2:....</p>
<p>und die ausgabe sieht so ungefähr aus:<br />
name1:paswort1:1:1....#:paswort1:1:1....#..##<br />
also irgend wie total verdreht</p>
<p>danke schon mal im vorraus</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/212550/fscanf-trennt-nicht</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 20:28:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/212550.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 07 May 2008 17:23:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to fscanf trennt : nicht on Wed, 07 May 2008 17:23:55 GMT]]></title><description><![CDATA[<p>guten abend,</p>
<p>in meinem code trennt fscanf mein : nicht.<br />
was mach ich da falsch?</p>
<pre><code class="language-cpp">// 
// File:   pwdsort.cc
// Author: xmo
//
// Created on 5. Mai 2008, 12:31
//

#include &lt;stdlib.h&gt;
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;string&gt;
#include &lt;sys/stat.h&gt;
using namespace std;
//
// 
//
string sortOption = &quot;name&quot;;
string path = &quot;/etc/password&quot;;
string newPath;
string synkom = &quot;pwdsort&quot;;
string myCin;
size_t found;
FILE * pFile;
char buffer [130];

struct pwdent {
char name[10];
char pwd[10];
int uid;
int gid;
char gcos[40];
char home[40];
char shell[20];
};
pwdent structs[100];

void checkKommando(string input)
{
  if(input.substr(0,synkom.length()) == synkom)
  {
      if(input.find(&quot; -&quot;) != string::npos)
      {         
          sortOption = input.substr(synkom.length()+2, 4); //4 muss ersetzt werden
          cout &lt;&lt; sortOption &lt;&lt; '\n'; //Testweise
      }

      if(input.rfind(&quot; &quot;) != string::npos &amp;&amp; (input.rfind(&quot; &quot;) + 1) != input.rfind(&quot;-&quot;))
      {
          path = input.substr(input.rfind(&quot; &quot;) + 1, input.length() - input.rfind(&quot; &quot;));
          cout &lt;&lt; path &lt;&lt; '\n'; //Testweise
      }

  }else cerr &lt;&lt; &quot;Syntax fehler&quot;;
}

// HIER IN DIESER FUNKTION IST DAS PROBLEM

void readFile()
{
   char* myPath = const_cast&lt;char*&gt;(path.c_str());
   pFile = fopen (myPath , &quot;r&quot;);
   if (pFile != NULL)
    {
       for(int i = 0 ; i &lt; !feof(pFile)&amp;&amp; i &lt; 1000 ; i++)
       {
        fscanf(pFile,&quot;%s:%s:%d:%d:%s:%s:%s\n&quot;,structs[i].name,structs[i].pwd,structs[i].uid,structs[i].gid,structs[i].gcos,structs[i].home,structs[i].shell);
       }
       fclose (pFile);
   }else cerr &lt;&lt; &quot;Pfad nicht gefunden&quot;;

  printf(&quot;%s#%s#%d#%d#%s#%s#%s&quot;,structs[0].name,structs[0].pwd,structs[0].uid,structs[0].gid,structs[0].gcos,structs[0].home,structs[0].shell);
}

int main(int argc, char** argv) {

    getline(cin, myCin);
    checkKommando(myCin);
    readFile();

    return (EXIT_SUCCESS);
}
</code></pre>
<p>die txt datei sie ungefähr so aus:<br />
name1:paswort1:1:1....<br />
name1:passwort2:2:2:....</p>
<p>und die ausgabe sieht so ungefähr aus:<br />
name1:paswort1:1:1....#:paswort1:1:1....#..##<br />
also irgend wie total verdreht</p>
<p>danke schon mal im vorraus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1505045</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1505045</guid><dc:creator><![CDATA[xmo]]></dc:creator><pubDate>Wed, 07 May 2008 17:23:55 GMT</pubDate></item><item><title><![CDATA[Reply to fscanf trennt : nicht on Wed, 07 May 2008 17:37:57 GMT]]></title><description><![CDATA[<p>Mische doch nicht die Funktionen von C und C++ <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1505049</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1505049</guid><dc:creator><![CDATA[ceplusplus*loggedoff]]></dc:creator><pubDate>Wed, 07 May 2008 17:37:57 GMT</pubDate></item><item><title><![CDATA[Reply to fscanf trennt : nicht on Wed, 07 May 2008 17:40:53 GMT]]></title><description><![CDATA[<p>Ich bin ein absuluter anfänger, keine ahnung was c und was c++ ist ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1505052</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1505052</guid><dc:creator><![CDATA[xmo]]></dc:creator><pubDate>Wed, 07 May 2008 17:40:53 GMT</pubDate></item><item><title><![CDATA[Reply to fscanf trennt : nicht on Thu, 08 May 2008 05:00:02 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">pwdent structs[100];
</code></pre>
<p>und</p>
<pre><code class="language-cpp">for(int i = 0 ; i &lt; !feof(pFile)&amp;&amp; i &lt; 1000 ; i++)
       {
        fscanf(pFile,&quot;%s:%s:%d:%d:%s:%s:%s\n&quot;,structs[i].name,structs[i].pwd,structs[i].uid,structs[i].gid,structs[i].gcos,structs[i].home,structs[i].shell);
       }
</code></pre>
<p>man beachte die 100 und die 1000 <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>zeig mal die zeile ndes Datei EXAKT wie sie da drin steihen, und die Ausgabe auch EXAKT...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1505214</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1505214</guid><dc:creator><![CDATA[BorisDieKlinge]]></dc:creator><pubDate>Thu, 08 May 2008 05:00:02 GMT</pubDate></item><item><title><![CDATA[Reply to fscanf trennt : nicht on Thu, 08 May 2008 06:05:14 GMT]]></title><description><![CDATA[<p>xmo schrieb:</p>
<blockquote>
<p>Ich bin ein absuluter anfänger, keine ahnung was c und was c++ ist ^^</p>
</blockquote>
<p>1. Thema C/C++</p>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt;    // C, zudem in C++ bitte wenn schon #include &lt;cstdlib&gt;
#include &lt;iostream&gt;    // C++
#include &lt;stdio.h&gt;     // C, zudem in C++ bitte wenn schon #include &lt;cstdio&gt; 
#include &lt;string&gt;      // C++
#include &lt;sys/stat.h&gt;  // Keine Ahnung...
</code></pre>
<p>In C++ verwendet man in der Regel auch weder printf noch scanf, sondern greift auf die Streamklassen zu (z.B. zum Einlesen/Ausgeben von Dateien fstream).</p>
<p>2. Globale Variablen<br />
Zudem sind globale Variablen in den aller seltesten Fällen sinnvoll.</p>
<p>3. Les dir ein Tutorial oder Buch (wie C++ Primer) durch</p>
<p>cu André</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1505228</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1505228</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Thu, 08 May 2008 06:05:14 GMT</pubDate></item></channel></rss>