<?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[wie argc, argv filtern?]]></title><description><![CDATA[<p>Ich scheitere gerade Erbärmlichkeit an C arrays.</p>
<p>Ich habe ein main Funktion von welcher ich eine andere 'program_main' Funktion aufrufe.</p>
<p>Das sieht ungefähr so aus:</p>
<pre><code>int main (int argc, char* argv[])
{
  program_main (argc, argv);
}
</code></pre>
<p>ich möchte jetzt argv filtern, und argc entsprechend verkleinern.</p>
<p>Mein naiver ansatz:</p>
<pre><code>int main (int argc, char* argv[])
{ 
  std::vector&lt;char*&gt; myargs ;

  for (int i = 0; i &lt; argc ; ++i)
  {
    // if filter ok 
    myargs.push_back(argv[i]);
  }

  program_main (myargs.size(), &amp;myargs[0]);
}
</code></pre>
<p>das scheint aber nicht zu funktionieren, program_main verabschiedet sich mit einem sigterm<br />
crash im Fall das myargs leer ist, und ist etwas drinnen wird es nicht erkannt.</p>
<p>Es scheint also das mir ein ganz wichtiges Detail entgeht, nur welches, wie kann ich argv filtern?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/339877/wie-argc-argv-filtern</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 16:56:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/339877.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 05 Oct 2016 07:55:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to wie argc, argv filtern? on Wed, 05 Oct 2016 07:55:08 GMT]]></title><description><![CDATA[<p>Ich scheitere gerade Erbärmlichkeit an C arrays.</p>
<p>Ich habe ein main Funktion von welcher ich eine andere 'program_main' Funktion aufrufe.</p>
<p>Das sieht ungefähr so aus:</p>
<pre><code>int main (int argc, char* argv[])
{
  program_main (argc, argv);
}
</code></pre>
<p>ich möchte jetzt argv filtern, und argc entsprechend verkleinern.</p>
<p>Mein naiver ansatz:</p>
<pre><code>int main (int argc, char* argv[])
{ 
  std::vector&lt;char*&gt; myargs ;

  for (int i = 0; i &lt; argc ; ++i)
  {
    // if filter ok 
    myargs.push_back(argv[i]);
  }

  program_main (myargs.size(), &amp;myargs[0]);
}
</code></pre>
<p>das scheint aber nicht zu funktionieren, program_main verabschiedet sich mit einem sigterm<br />
crash im Fall das myargs leer ist, und ist etwas drinnen wird es nicht erkannt.</p>
<p>Es scheint also das mir ein ganz wichtiges Detail entgeht, nur welches, wie kann ich argv filtern?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2510610</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2510610</guid><dc:creator><![CDATA[kurze_frage]]></dc:creator><pubDate>Wed, 05 Oct 2016 07:55:08 GMT</pubDate></item><item><title><![CDATA[Reply to wie argc, argv filtern? on Wed, 05 Oct 2016 08:19:58 GMT]]></title><description><![CDATA[<p>Der gezeigte Code sieht korrekt aus. Die Funktion wird wohl nicht erwarten, dass ihr etwas vorenthalten wird. argv[0] = Programmname? argv[argc] = Nullpointer?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2510614</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2510614</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Wed, 05 Oct 2016 08:19:58 GMT</pubDate></item><item><title><![CDATA[Reply to wie argc, argv filtern? on Wed, 05 Oct 2016 08:28:45 GMT]]></title><description><![CDATA[<p>Debugge das doch mal. Vermutlich stimmt da etwas mit deinem Filter nicht. Du vergleichst hoffentlich nicht char* per &quot;==&quot;?</p>
<p>Abgesehen davon: Könntest du nicht program_main direkt den gefilterten vector übergeben? Oder werden da zwingen dieselben Parameter erwartet wie bei der main?</p>
<p>edit: wow, Beitrag #1000!!! Ich hoffe, ein hilfreicher <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2510616</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2510616</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 05 Oct 2016 08:28:45 GMT</pubDate></item><item><title><![CDATA[Reply to wie argc, argv filtern? on Wed, 05 Oct 2016 08:40:10 GMT]]></title><description><![CDATA[<p>cool manni66</p>
<p>dummer weise sah meiner Filter Schleife so aus</p>
<pre><code>for (int i = 1; i &lt; argc ; ++i)
  {
    // if filter ok
    myargs.push_back(argv[i]);
  }
</code></pre>
<p>und da hat argv[0] im vector gefehlt, und das war ganz schlecht</p>
<p>fix:</p>
<pre><code>myargs.push_back(argv[0]);
  for (int i = 1; i &lt; argc ; ++i)
  {
    // if filter ok
    myargs.push_back(argv[i]);
  }
</code></pre>
<p>jetzt funktioniert es wie es soll.</p>
<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2510619</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2510619</guid><dc:creator><![CDATA[kurze_frage]]></dc:creator><pubDate>Wed, 05 Oct 2016 08:40:10 GMT</pubDate></item></channel></rss>