<?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[Sudoku-Solver mit C]]></title><description><![CDATA[<p>Hallo, ich hab in der Schule eine Aufgabe bekommen, wür mussen ein Sudoku-Solver programmieren in C.Also das Sudoku selbst wird aus Datei gelesen und dann auf BS gelöst ausgegeben.Und ich komme nicht weiter....Es werden irgendwelche Zahlen ausgegeben.</p>
<pre><code class="language-cpp">#include&lt;stdlib.h&gt;
#include&lt;string.h&gt;
#include&lt;stdio.h&gt;
int check (int,int,int);
int versuch(int);
void ausgabe();
int matrix[9][9];
FILE *datei;
char datname[15];

int check(int a, int b, int u) {
  int i,j;
  if ( matrix[a])       return 0;
  for (i = 0; i &lt; 9; i++) { 
    if (u == matrix[a][i]) return 0;
    if (u == matrix[i][b]) return 0;
  }
  for ( i = a - a%3 ; i &lt; a - a%3 + 3; i++) 
    for (j = b - b%3 ; j &lt; b - b%3 + 3; j++)
      if (u == matrix[i][j])
	return 0;
  return 1;
}
int versuche(int k) {  /* k --&gt; k/9 k%9 */
  int i, q;
  while ( k&lt;=80 &amp;&amp; matrix[k/9][k%9] ) k++; /* naechstes freies Feld?  */
 //if ( k == 81 ) return 1;               /* alles belegt, fertig    */
  for ( q=0, i=1 ; q == 0 &amp;&amp; i &lt;= 9 ; i++) { 
    if ( check(k/9, k%9, i) ) {  /* teste das Feld k mit allen i    */
	matrix[k/9][k%9] = i;
	if (k == 80) q = 1;      /* falls letztes Feld, Erfolg: q=1 */
	else                    
	  if (  (q = versuche(k+1) ) == 0) /* sonst naechstes Feld  */
	    matrix[k/9][k%9] = 0;  /* Falls erfolglos, Ruecksetzen    */
      }
  }
  return q;
}

int main()
{
int i,j,z;

printf(&quot;Bitte Dateinamen der einzulesenden Datei eingeben!\n Eingabe: &quot;); 
  scanf (&quot;%s&quot;,datname);
datei=fopen(datname,&quot;r&quot;);
   if (datei==NULL)
       printf(&quot;Ffehler!Datei konnte nicht geöffnet werden!!:&quot;);
       printf(&quot;\nDer vorgegebene Sudoku aus Datei!!\n&quot;);
  do{                  
     for(i=0;i&lt;9;i++)
         {   for(j=0;j&lt;=9;j++)
               { z=fgetc(datei);
                printf (&quot;|%c&quot;, z);
                matrix[i][j]=z;
               }                 
         }printf (&quot;\nFertig\n&quot;);
         }    
  while ((z=fgetc(datei))!=EOF);
versuche(0);
ausgabe();
return 0;
}
void ausgabe()
{
int i,j;

printf(&quot;|-|-|-|-|-|-|-|-|-|\n&quot;);
        for (i=0;i&lt;9;i++){
       for (j=0;j&lt;=9;j++) {
         printf (&quot;|%d&quot;, matrix[i][j]); }}      
         printf(&quot;\n\n----Fertig-----&quot;);     
}
</code></pre>
<p>**<br />
UNd die Datei sieht so aus:<br />
sudoku1.txt<br />
[b]090604750<br />
406000000<br />
700508609<br />
007402006<br />
860301074<br />
900705800<br />
502107008<br />
000000305<br />
083209010**</p>
<p>Was ist falsch?ICh sitze schon 2 Tage und weiß nicht mehr wo ich suchen soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/228483/sudoku-solver-mit-c</link><generator>RSS for Node</generator><lastBuildDate>Tue, 29 Sep 2026 14:54:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/228483.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 28 Nov 2008 19:41:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Sudoku-Solver mit C on Fri, 28 Nov 2008 19:41:28 GMT]]></title><description><![CDATA[<p>Hallo, ich hab in der Schule eine Aufgabe bekommen, wür mussen ein Sudoku-Solver programmieren in C.Also das Sudoku selbst wird aus Datei gelesen und dann auf BS gelöst ausgegeben.Und ich komme nicht weiter....Es werden irgendwelche Zahlen ausgegeben.</p>
<pre><code class="language-cpp">#include&lt;stdlib.h&gt;
#include&lt;string.h&gt;
#include&lt;stdio.h&gt;
int check (int,int,int);
int versuch(int);
void ausgabe();
int matrix[9][9];
FILE *datei;
char datname[15];

int check(int a, int b, int u) {
  int i,j;
  if ( matrix[a])       return 0;
  for (i = 0; i &lt; 9; i++) { 
    if (u == matrix[a][i]) return 0;
    if (u == matrix[i][b]) return 0;
  }
  for ( i = a - a%3 ; i &lt; a - a%3 + 3; i++) 
    for (j = b - b%3 ; j &lt; b - b%3 + 3; j++)
      if (u == matrix[i][j])
	return 0;
  return 1;
}
int versuche(int k) {  /* k --&gt; k/9 k%9 */
  int i, q;
  while ( k&lt;=80 &amp;&amp; matrix[k/9][k%9] ) k++; /* naechstes freies Feld?  */
 //if ( k == 81 ) return 1;               /* alles belegt, fertig    */
  for ( q=0, i=1 ; q == 0 &amp;&amp; i &lt;= 9 ; i++) { 
    if ( check(k/9, k%9, i) ) {  /* teste das Feld k mit allen i    */
	matrix[k/9][k%9] = i;
	if (k == 80) q = 1;      /* falls letztes Feld, Erfolg: q=1 */
	else                    
	  if (  (q = versuche(k+1) ) == 0) /* sonst naechstes Feld  */
	    matrix[k/9][k%9] = 0;  /* Falls erfolglos, Ruecksetzen    */
      }
  }
  return q;
}

int main()
{
int i,j,z;

printf(&quot;Bitte Dateinamen der einzulesenden Datei eingeben!\n Eingabe: &quot;); 
  scanf (&quot;%s&quot;,datname);
datei=fopen(datname,&quot;r&quot;);
   if (datei==NULL)
       printf(&quot;Ffehler!Datei konnte nicht geöffnet werden!!:&quot;);
       printf(&quot;\nDer vorgegebene Sudoku aus Datei!!\n&quot;);
  do{                  
     for(i=0;i&lt;9;i++)
         {   for(j=0;j&lt;=9;j++)
               { z=fgetc(datei);
                printf (&quot;|%c&quot;, z);
                matrix[i][j]=z;
               }                 
         }printf (&quot;\nFertig\n&quot;);
         }    
  while ((z=fgetc(datei))!=EOF);
versuche(0);
ausgabe();
return 0;
}
void ausgabe()
{
int i,j;

printf(&quot;|-|-|-|-|-|-|-|-|-|\n&quot;);
        for (i=0;i&lt;9;i++){
       for (j=0;j&lt;=9;j++) {
         printf (&quot;|%d&quot;, matrix[i][j]); }}      
         printf(&quot;\n\n----Fertig-----&quot;);     
}
</code></pre>
<p>**<br />
UNd die Datei sieht so aus:<br />
sudoku1.txt<br />
[b]090604750<br />
406000000<br />
700508609<br />
007402006<br />
860301074<br />
900705800<br />
502107008<br />
000000305<br />
083209010**</p>
<p>Was ist falsch?ICh sitze schon 2 Tage und weiß nicht mehr wo ich suchen soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1622623</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1622623</guid><dc:creator><![CDATA[milka]]></dc:creator><pubDate>Fri, 28 Nov 2008 19:41:28 GMT</pubDate></item><item><title><![CDATA[Reply to Sudoku-Solver mit C on Fri, 28 Nov 2008 19:51:00 GMT]]></title><description><![CDATA[<p>So weit reduzieren bis du wieder nachvollziehen kannst was überhaupt passiert.<br />
Oder nochmal alles von Grund auf durchgehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1622626</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1622626</guid><dc:creator><![CDATA[Tipper]]></dc:creator><pubDate>Fri, 28 Nov 2008 19:51:00 GMT</pubDate></item><item><title><![CDATA[Reply to Sudoku-Solver mit C on Fri, 28 Nov 2008 19:53:05 GMT]]></title><description><![CDATA[<p>Das hier ist das C++ Subforum...</p>
<p>Trotzdem:<br />
Kann es ein, dass du die Char-Werte der einzelnen Zahlen statt deren Zahlenwerte zum Rechnen benutzt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1622628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1622628</guid><dc:creator><![CDATA[The-Kenny]]></dc:creator><pubDate>Fri, 28 Nov 2008 19:53:05 GMT</pubDate></item><item><title><![CDATA[Reply to Sudoku-Solver mit C on Fri, 28 Nov 2008 19:55:02 GMT]]></title><description><![CDATA[<p>Hab ich schon gemacht..Mit Debugger auch..Und bei Funktionsaufruf versuch(0) vermute ich dass er nicht die Werte selbst übergibt sondern nur adressen..Trotzdem weiß ich nicht, was ich da korrigiren soll. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1622629</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1622629</guid><dc:creator><![CDATA[milka]]></dc:creator><pubDate>Fri, 28 Nov 2008 19:55:02 GMT</pubDate></item><item><title><![CDATA[Reply to Sudoku-Solver mit C on Fri, 28 Nov 2008 19:57:27 GMT]]></title><description><![CDATA[<p>Du bist anscheinend noch zu wenig genau mit dem Debugger durchgegangen. Kontrollier doch mal die Werte der Variablen zur Laufzeit. Dann siehst du auch, wo etwas nicht mehr stimmt.</p>
<p>P.S. Die Funktion <code>versuche()</code> hat einen <code>int</code> als Parameter, wie kommst du auf Adressen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1622632</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1622632</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Fri, 28 Nov 2008 19:57:27 GMT</pubDate></item><item><title><![CDATA[Reply to Sudoku-Solver mit C on Fri, 28 Nov 2008 21:01:27 GMT]]></title><description><![CDATA[<p>Ich habs!!! Vielen Dank für ihre Hilfe.Das PRoblem war (mit Debuger gefunden) bei Zeile 53.Da muss man noch den eingelesenen Wert aus ASCII in nummerischen Wert umwandeln.Und dann in matrix[i][j] schreiben...Es funktioniert!!!!<br />
<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>
]]></description><link>https://www.c-plusplus.net/forum/post/1622645</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1622645</guid><dc:creator><![CDATA[milka]]></dc:creator><pubDate>Fri, 28 Nov 2008 21:01:27 GMT</pubDate></item></channel></rss>