kostenloser Webspace werbefrei: lima-city


Fehler in C Programm bzw. Unwissen

lima-cityForumProgrammiersprachenC/C++ und D

  1. Autor dieses Themas

    infinitysounds

    Kostenloser Webspace von infinitysounds

    infinitysounds hat kostenlosen Webspace.

    HI Leute,

    Ich habe mit einem ref="/tag/programm">Programm ein kleines Problem: An der kritischen Stelle bricht es ab.
    Ich weiß nicht, ob das, was ich versucht habe funktionieren kann, aber es wäre schön, wnen mir jemand seine Meinung dazu sagen könnte;

    Das Programm soll aus zwei Aneinanderkettungen von drei Buchstaben eine Zahl ausrechnen, später eine Prozentzahl.
    Die Idee bzw. der Auftrag wurde mir von einem Freund gegeben ;) ich denke mal jeder kann erkennen, worauf das ganze hinausläuft :-P
    Der CODE:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <mathj.h>
    
    const int a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10,k=11,l=12,m=13,n=14,o=15,p=16,q=17,r=18,s=19,t=20,u=21,v=22,w=23,x=24,y=25,z=26;
    
    int main(int argc, char *argv[])
    {
      char werte[25][25];
      int zahl1;
      int zahl2;
      int zahl3;
      char* your[2];
      char* her[2];
     
      for(zahl1=0,zahl3=1;zahl1<27;zahl1+=3)
      {
            for(zahl2=0;zahl2<26;zahl2++)
            {
            werte[zahl1][zahl2] = zahl3;
            }
      }
    
      for(zahl1=1,zahl3=2;zahl1<27;zahl1+=3)
      {
            for(zahl2=0;zahl2<26;zahl2++)
            {
            werte[zahl1][zahl2] = zahl3;
            }
      }
      for(zahl1=2,zahl3=3;zahl1<27;zahl1+=3)
      {
            for(zahl2=0;zahl2<26;zahl2++)
            {
            werte[zahl1][y] = zahl3;
            }
      }
      for(zahl1=0;zahl1<=25;zahl1++)
      {
            werte[zahl1][zahl1]=0;
      }
      printf("Geben Sie die ersten 3 Buchstaben ihres Vornamens ein: ");
      scanf("%s",&your);
      system("cls");
      printf("Geben Sie die ersten 3 Buchstaben des  Namens Ihres Schwarmes ein: ");
      scanf("%s",&her);
      system("cls");
      
    
      for(zahl1=0;zahl1<=2;zahl1++)  {
            if((strcmp(your[zahl1],NaN[zahl1])==0)) your[zahl1] = a;
            /*if((strcmp(your[zahl1],"b")==0)) your[zahl1] = b;
            if((strcmp(your[zahl1],"c")==0)) your[zahl1] = c;
            if((strcmp(your[zahl1],"d")==0)) your[zahl1] = d;
            if((strcmp(your[zahl1],"e")==0)) your[zahl1] = e;
            if((strcmp(your[zahl1],"f")==0)) your[zahl1] = f;
            if((strcmp(your[zahl1],"g")==0)) your[zahl1] = g;
            if((strcmp(your[zahl1],"h")==0)) your[zahl1] = h;
            if((strcmp(your[zahl1],"i")==0)) your[zahl1] = i;
            if((strcmp(your[zahl1],"j")==0)) your[zahl1] = j;
            if((strcmp(your[zahl1],"k")==0)) your[zahl1] = k;
            if((strcmp(your[zahl1],"l")==0)) your[zahl1] = l;
            if((strcmp(your[zahl1],"m")==0)) your[zahl1] = m;
            if((strcmp(your[zahl1],"n")==0)) your[zahl1] = n;
            if((strcmp(your[zahl1],"o")==0)) your[zahl1] = o;
            if((strcmp(your[zahl1],"p")==0)) your[zahl1] = p;
            if((strcmp(your[zahl1],"q")==0)) your[zahl1] = q;
            if((strcmp(your[zahl1],"r")==0)) your[zahl1] = r;
            if((strcmp(your[zahl1],"s")==0)) your[zahl1] = s;
            if((strcmp(your[zahl1],"t")==0)) your[zahl1] = t;
            if((strcmp(your[zahl1],"u")==0)) your[zahl1] = u;
            if((strcmp(your[zahl1],"v")==0)) your[zahl1] = v;
            if((strcmp(your[zahl1],"w")==0)) your[zahl1] = w;
            if((strcmp(your[zahl1],"x")==0)) your[zahl1] = x;
            if((strcmp(your[zahl1],"y")==0)) your[zahl1] = y;
            if((strcmp(your[zahl1],"z")==0)) your[zahl1] = z;*/
            //her
            if((strcmp(her[zahl1],NaN[zahl1])==0)) her[zahl1] = a;
            /*if((strcmp(her[zahl1],"b")==0)) her[zahl1] = b;
            if((strcmp(her[zahl1],"c")==0)) her[zahl1] = c;
            if((strcmp(her[zahl1],"d")==0)) her[zahl1] = d;
            if((strcmp(her[zahl1],"e")==0)) her[zahl1] = e;
            if((strcmp(her[zahl1],"f")==0)) her[zahl1] = f;
            if((strcmp(her[zahl1],"g")==0)) her[zahl1] = g;
            if((strcmp(her[zahl1],"h")==0)) her[zahl1] = h;
            if((strcmp(her[zahl1],"i")==0)) her[zahl1] = i;
            if((strcmp(her[zahl1],"j")==0)) her[zahl1] = j;
            if((strcmp(her[zahl1],"k")==0)) her[zahl1] = k;
            if((strcmp(her[zahl1],"l")==0)) her[zahl1] = l;
            if((strcmp(her[zahl1],"m")==0)) her[zahl1] = m;
            if((strcmp(her[zahl1],"n")==0)) her[zahl1] = n;
            if((strcmp(her[zahl1],"o")==0)) her[zahl1] = o;
            if((strcmp(her[zahl1],"p")==0)) her[zahl1] = p;
            if((strcmp(her[zahl1],"q")==0)) her[zahl1] = q;
            if((strcmp(her[zahl1],"r")==0)) her[zahl1] = r;
            if((strcmp(her[zahl1],"s")==0)) her[zahl1] = s;
            if((strcmp(her[zahl1],"t")==0)) her[zahl1] = t;
            if((strcmp(her[zahl1],"u")==0)) her[zahl1] = u;
            if((strcmp(her[zahl1],"v")==0)) her[zahl1] = v;
            if((strcmp(her[zahl1],"w")==0)) her[zahl1] = w;
            if((strcmp(her[zahl1],"x")==0)) her[zahl1] = x;
            if((strcmp(her[zahl1],"y")==0)) her[zahl1] = y;
            if((strcmp(her[zahl1],"z")==0)) her[zahl1] = z;*/
            
    }
      int res1 = (int)your[0]+(int)your[1]+(int)your[2];
      int res2 = (int)her[0]+(int)her[1]+(int)her[2];
      int res;
      res=res1-res2;
      printf("%d",res);
      system("PAUSE");
      return 0;
    }


    mfg,

    InfinitySounds

    PS: Die Bibliothek math.j sieht so aus:

    #include <math.h>
    
    
    
    char* NaN={"a,b,c,d,e,f,g,h,i,j,k,l,o,m,n,o,p,q,r,s,t,u,v,w,x,y,z"};
    
    int fak(int x)
    {
        if(x<=0) return 1;
        if(x!=NaN) return x * fak(x-1);
    }
    
    double expo(double bas,int expo)
    {
        double res;
        int zahl;
        res = bas;
        for(zahl=1;zahl<expo;zahl++)
        {
            res = res * bas;
        }
        return res;
    }
    double deg2rad(double deg)
    {
        double radiant;
        radiant = ((deg/10)/(360/10))*(2*M_PI);
        return radiant;
    }
    
    double sinus_function(double radiant)
    {
        double resu;
        double rad=radiant;
        resu=rad-((expo(rad,3))/fak(3))+((expo(rad,5))/fak(5))+((expo(rad,7))/fak(7))-((expo(rad,9))/fak(9))+((expo(rad,11))/fak(11))-((expo(rad,13))/fak(13))+((expo(rad,15))/fak(15))-((expo(rad,17))/fak(17))+((expo(rad,19))/fak(19))-((expo(rad,21))/fak(21))+((expo(rad,23))/fak(23));
        return resu;
    }
    
    
    double sinus_d(double deg)
    {
        double result;
        double r = deg2rad(deg);
        result = sinus_function(r);
        return  result;
    }
    
    int vonbis(int x)
    {
       
        if(x<=0) return 0;
        if(x!=NaN) return x + vonbis(x-1);
    }
    
    char* divisable(int div1,int div2)
    {
    
    int erg;
    erg = div1%div2;
    if(erg==0)
    {
        return "is";
    }
    else
    {
    return "is not";
    }
    }
    
    char* prim(int check)
    {
        long zahl;
        long trick;
        trick=0;
        for(zahl = 2;zahl<sqrt(check);zahl++)
        {
            if(check%zahl == 0) trick=+1;
        }
        if(trick != 0)  return "is not a";
    
        if(trick == 0)  return "is a";
    }
    
    float calc(float math1,float math2,char sign)
    {
        float out;
        if(sign == '+')    out = math1 + math2;
        else if(sign == '-')    out = math1 - math2;
        else if(sign == '*')    out = math1 * math2;
        else if(sign == '/')    out = math1 / math2;
        else return 0;
        //if( out - floor( out ) == .0f )    printf("Ergebnis: %.0f\n",out);
        return out;
    }
  2. Diskutiere mit und stelle Fragen: Jetzt kostenlos anmelden!

    lima-city: Gratis werbefreier Webspace für deine eigene Homepage

  3. Und wo ist diese kritische Stelle? Wenn du Hilfe von uns erwartest, musst du uns schon etwas entgegen kommen, denn sonst dauert es unnötig lange, bis man durchblickt, wo der Fehler sitzt.

    Und dein Code enthält sehr viele unnötige Wiederholungen. Das bläht das ganze unnötig auf. Versuch das mal in Schleifen oder eigene Funktionen zu packen, so das das ganze kompakter wird.

    Und ist dir bewusst, dass ein 'char' eigentlich eine Zahl ist? Wenn du das berücksichtigst, kannst du auch ganz einfach mit "Buchstaben" rechnen und deinen Code vereinfachen. Näheres dazu findest du in einer ASCII-Tabelle.
  4. Autor dieses Themas

    infinitysounds

    Kostenloser Webspace von infinitysounds

    infinitysounds hat kostenlosen Webspace.

    bladehunter schrieb:
    Und wo ist diese kritische Stelle? Wenn du Hilfe von uns erwartest, musst du uns schon etwas entgegen kommen, denn sonst dauert es unnötig lange, bis man durchblickt, wo der Fehler sitzt.

    Und dein Code enthält sehr viele unnötige Wiederholungen. Das bläht das ganze unnötig auf. Versuch das mal in Schleifen oder eigene Funktionen zu packen, so das das ganze kompakter wird.

    Und ist dir bewusst, dass ein 'char' eigentlich eine Zahl ist? Wenn du das berücksichtigst, kannst du auch ganz einfach mit "Buchstaben" rechnen und deinen Code vereinfachen. Näheres dazu findest du in einer ASCII-Tabelle.


    Das schwierige für mich ist, den String in einzelne chars aufzulösen... das mit den Wiederholungen ist hauptsächlich wegen debugging/weil ich noch nicht soooo gut bin ;)

    Auf die ASCII Variante hätte ich auch kommen können ....-.-

    dennoch bleibt das problem :(
  5. Du hast immer noch nicht gesagt, wo jetzt diese blöde kritische Stelle ist. Und wenn du das im nachfolgenden Post immer noch nicht erwähnst, wird hier geschlossen. Ich (und viele andere) haben keine Lust das selber komplett durchzulesen.


    Das schwierige für mich ist, den String in einzelne chars aufzulösen

    Ein String ist ein Array von chars. meinString[0] liefert dir den ersten Char. meinString[1] den zweiten usw.


    das mit den Wiederholungen ist hauptsächlich wegen debugging/weil ich noch nicht soooo gut bin ;)

    Das ist definitiv die falsche Denkweise. Computer sind dazu da, um stupide Arbeit zu erledigen. Copy&Paste-Coding ist böse.

    Du solltest dir Arrays in C mal genauer anschauen.


    Versuche das Problem so weit wie es geht einzukreisen und sage uns dann, wo der Schuh drückt. Dann finden sich eventuell auch Leute, die dir helfen wollen.

    Beitrag zuletzt geändert: 27.9.2011 18:43:20 von bladehunter
  6. Generell würde mich auch mal interessieren, was dein Programm genau tun soll... bitte beschreibe mit eigenen Worten was du insgesamt tun möchtest.

    Ich habe deinen Code nur überflogen, und leider feststellen müssen, dass du noch recht kompliziert denkst. Es geht nicht darum einen möglichst kurzen Code zu verfassen, aber dieser sollte schon irgendwie "lesbar" sein. Aber da du noch am "Anfang" bist, kann man ein Auge zudrücken, Besserung solltest du trotzdem geloben:-) Achso, und die Tipps von Bladehunter sind immer gut, wer sich da dran hält kommt schneller zum Ziel.

    Also, was mir aufgefallen ist, sind diese beiden Stellen:

    char* your[2];
      char* her[2];
    und
    int res1 = (int)your[0]+(int)your[1]+(int)your[2];
      int res2 = (int)her[0]+(int)her[1]+(int)her[2];
    Stürzt dein Programm an der unteren Stelle ab? Wenn ja, ersetze char * durch char. Und erkläre mir bitte (wieder mit eigenen Worten), warum das so sein muss (oder auch nicht^^).

    PS: merkwürdiger Stil ein zweidimensionales Array zu initialisieren... geht bestimmt auch einfacher:-)
    PPS: meterlange if-Abfragen können sich erübrigen, wenn du Wissen über ASCII einstreust (wie Blade schon gesagt hat)

    Beitrag zuletzt geändert: 27.9.2011 19:02:16 von tangoal
  7. Ich denke, der Grund, warum dein Programm abstürzt, steckt in der Definition, bzw. Benutzung des Werte-Arrays:

    char werte[25][25];
     ...
      for(zahl1=0,zahl3=1;zahl1<27;zahl1+=3)
      {
          ...
          werte[zahl1][zahl2] = zahl3;...
      }


    Du definierst das Array in der ersten Dimension mit 25, das bedeutet, dass du mit den Indizes 0 bis 24 darauf zugreifen darfst. In der Schleife jedoch nutzt du auch den Index 25: Im achten Schleifendurchlauf ist zahl1 = 1 + 8*3 = 25 > 24. Somit hast du einen unerlaubten Speicherzugriff, welcher zum Absturz führt. Die übrigen Schleifen musst du natürlich auch noch diesbezüglich überprüfen...

    Eine (englische) Meldung mit diesem Inhalt sollte bei dem Absturz erscheinen, sodass ich bladehunter Recht geben muss: ein paar mehr informationen, wie z.B. die Fehlermeldung sowie die ungefähre Fehlerstelle, falls du schon ein wenig debugged hast, wären sehr hilfreich (gewesen).

    Edit: das, was tangoal gesagt hat, ist noch ein schwerer Fehler, den ich ganz übersehen habe...wie hast du das überhaupt kompiliert bekommen?


    Beitrag zuletzt geändert: 27.9.2011 19:18:11 von nomis
  8. Autor dieses Themas

    infinitysounds

    Kostenloser Webspace von infinitysounds

    infinitysounds hat kostenlosen Webspace.

    bladehunter schrieb:
    Du hast immer noch nicht gesagt, wo jetzt diese blöde kritische Stelle ist. Und wenn du das im nachfolgenden Post immer noch nicht erwähnst, wird hier geschlossen. Ich (und viele andere) haben keine Lust das selber komplett durchzulesen.


    Die kritische Stelle war hier:
    for(zahl1=0;zahl1<=2;zahl1++)  {
            if((strcmp(your[zahl1],NaN[zahl1])==0)) your[zahl1] = a;
            /*if((strcmp(your[zahl1],"b")==0)) your[zahl1] = b;
            if((strcmp(your[zahl1],"c")==0)) your[zahl1] = c;
            if((strcmp(your[zahl1],"d")==0)) your[zahl1] = d;
            if((strcmp(your[zahl1],"e")==0)) your[zahl1] = e;
            if((strcmp(your[zahl1],"f")==0)) your[zahl1] = f;
            if((strcmp(your[zahl1],"g")==0)) your[zahl1] = g;
            if((strcmp(your[zahl1],"h")==0)) your[zahl1] = h;
            if((strcmp(your[zahl1],"i")==0)) your[zahl1] = i;
            if((strcmp(your[zahl1],"j")==0)) your[zahl1] = j;
            if((strcmp(your[zahl1],"k")==0)) your[zahl1] = k;
            if((strcmp(your[zahl1],"l")==0)) your[zahl1] = l;
            if((strcmp(your[zahl1],"m")==0)) your[zahl1] = m;
            if((strcmp(your[zahl1],"n")==0)) your[zahl1] = n;
            if((strcmp(your[zahl1],"o")==0)) your[zahl1] = o;
            if((strcmp(your[zahl1],"p")==0)) your[zahl1] = p;
            if((strcmp(your[zahl1],"q")==0)) your[zahl1] = q;
            if((strcmp(your[zahl1],"r")==0)) your[zahl1] = r;
            if((strcmp(your[zahl1],"s")==0)) your[zahl1] = s;
            if((strcmp(your[zahl1],"t")==0)) your[zahl1] = t;
            if((strcmp(your[zahl1],"u")==0)) your[zahl1] = u;
            if((strcmp(your[zahl1],"v")==0)) your[zahl1] = v;
            if((strcmp(your[zahl1],"w")==0)) your[zahl1] = w;
            if((strcmp(your[zahl1],"x")==0)) your[zahl1] = x;
            if((strcmp(your[zahl1],"y")==0)) your[zahl1] = y;
            if((strcmp(your[zahl1],"z")==0)) your[zahl1] = z;*/
            //her
            if((strcmp(her[zahl1],NaN[zahl1])==0)) her[zahl1] = a;
            /*if((strcmp(her[zahl1],"b")==0)) her[zahl1] = b;
            if((strcmp(her[zahl1],"c")==0)) her[zahl1] = c;
            if((strcmp(her[zahl1],"d")==0)) her[zahl1] = d;
            if((strcmp(her[zahl1],"e")==0)) her[zahl1] = e;
            if((strcmp(her[zahl1],"f")==0)) her[zahl1] = f;
            if((strcmp(her[zahl1],"g")==0)) her[zahl1] = g;
            if((strcmp(her[zahl1],"h")==0)) her[zahl1] = h;
            if((strcmp(her[zahl1],"i")==0)) her[zahl1] = i;
            if((strcmp(her[zahl1],"j")==0)) her[zahl1] = j;
            if((strcmp(her[zahl1],"k")==0)) her[zahl1] = k;
            if((strcmp(her[zahl1],"l")==0)) her[zahl1] = l;
            if((strcmp(her[zahl1],"m")==0)) her[zahl1] = m;
            if((strcmp(her[zahl1],"n")==0)) her[zahl1] = n;
            if((strcmp(her[zahl1],"o")==0)) her[zahl1] = o;
            if((strcmp(her[zahl1],"p")==0)) her[zahl1] = p;
            if((strcmp(her[zahl1],"q")==0)) her[zahl1] = q;
            if((strcmp(her[zahl1],"r")==0)) her[zahl1] = r;
            if((strcmp(her[zahl1],"s")==0)) her[zahl1] = s;
            if((strcmp(her[zahl1],"t")==0)) her[zahl1] = t;
            if((strcmp(her[zahl1],"u")==0)) her[zahl1] = u;
            if((strcmp(her[zahl1],"v")==0)) her[zahl1] = v;
            if((strcmp(her[zahl1],"w")==0)) her[zahl1] = w;
            if((strcmp(her[zahl1],"x")==0)) her[zahl1] = x;
            if((strcmp(her[zahl1],"y")==0)) her[zahl1] = y;
            if((strcmp(her[zahl1],"z")==0)) her[zahl1] = z;*/
            
    }
      int res1 = (int)your[0]+(int)your[1]+(int)your[2];
      int res2 = (int)her[0]+(int)her[1]+(int)her[2];
      int res;
      res=res1-res2;
      printf("%d",res);
      system("PAUSE");
      return 0;
    }


    d.h. nach dem scanf, da ich danach keine ausgabe mehr habe, weiß ich aber nicht genau wo, ist jetzt aber egal, ich löse das jetzt per ASCII, danke Bladehunter und nomis
  9. Wenn das Programm es so weit schafft, lag ich mit meinem Fehler wohl Falsch. Aber anscheinend hast du den Post von tangoal nich gelesen (zumindest hast du in deiner Antwort nichts darüber geschrieben). Der Fehler, den er gefunden hat, würde auch zu der Stelle passen:
    tangoal schrieb:
    Generell [...]

    Also, was mir aufgefallen ist, sind diese beiden Stellen:

    char* your[2];
      char* her[2];
    und
    int res1 = (int)your[0]+(int)your[1]+(int)your[2];
      int res2 = (int)her[0]+(int)her[1]+(int)her[2];
    Stürzt dein Programm an der unteren Stelle ab? Wenn ja, ersetze char * durch char.
    [...]

    Also schau dir das nochmal an!
  10. Autor dieses Themas

    infinitysounds

    Kostenloser Webspace von infinitysounds

    infinitysounds hat kostenlosen Webspace.

    nomis schrieb:
    Wenn das Programm es so weit schafft, lag ich mit meinem Fehler wohl Falsch. Aber anscheinend hast du den Post von tangoal nich gelesen (zumindest hast du in deiner Antwort nichts darüber geschrieben). Der Fehler, den er gefunden hat, würde auch zu der Stelle passen:
    tangoal schrieb:
    Generell [...]

    Also, was mir aufgefallen ist, sind diese beiden Stellen:

    char* your[2];
      char* her[2];
    und
    int res1 = (int)your[0]+(int)your[1]+(int)your[2];
      int res2 = (int)her[0]+(int)her[1]+(int)her[2];
    Stürzt dein Programm an der unteren Stelle ab? Wenn ja, ersetze char * durch char.
    [...]

    Also schau dir das nochmal an!


    Sorry, nein, ich hatte Tangoals antwort gelesen (und umgesetzt) deine übrigens aus irgendeinem Grund nihct :confused:

    Wie auch immer.. mit mehrdimensionalen arrays habe ich schon viel gearbeitet ;) deshalb denke ich, dass der fehler dort nicht liegt...


    Ist DevC++ denn kein guter Compiler?
  11. Hallo infinitysounds,

    ich habe jetzt mal ein paar Kommentare eingefügt:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "mathj.h"
    
    char* NaN={"a,b,c,d,e,f,g,h,i,j,k,l,o,m,n,o,p,q,r,s,t,u,v,w,x,y,z"};
    const int a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10,k=11,l=12,m=13,n=14,o=15,p=16,q=17,r=18,s=19,t=20,u=21,v=22,w=23,x=24,y=25,z=26;
    
    int main(int argc, char *argv[])
    {
      char werte[25][25];
      int zahl1;
      int zahl2;
      int zahl3;
      char* your[2];
      char* her[2];
    
      /* 1. Fehler:
         Iteration bis werte[24][25] obwohl man nur bis
         werte[24][24] gehen darf
         -> Speicherzugriffsverletzung
      */
      for(zahl1=0,zahl3=1;zahl1<27;zahl1+=3)
      {
            for(zahl2=0;zahl2<26;zahl2++)
            {
            werte[zahl1][zahl2] = zahl3;
            }
      }
    
      /* 2. Fehler:
         Iteration bis werte[25][25] obwohl man nur bis
         werte[24][24] gehen darf
         -> Speicherzugriffsverletzung
      */
      for(zahl1=1,zahl3=2;zahl1<27;zahl1+=3)
      {
            for(zahl2=0;zahl2<26;zahl2++)
            {
            werte[zahl1][zahl2] = zahl3;
            }
      }
    
      /* 3. Fehler:
         Iteration bis werte[26][25] obwohl man nur bis
         werte[24][24] gehen darf
         -> Speicherzugriffsverletzung
      */
      for(zahl1=2,zahl3=3;zahl1<27;zahl1+=3)
      {
            for(zahl2=0;zahl2<26;zahl2++)
            {
            werte[zahl1][y] = zahl3;
            }
      }
      for(zahl1=0;zahl1<=25;zahl1++)
      {
            werte[zahl1][zahl1]=0;
      }
      printf("Geben Sie die ersten 3 Buchstaben ihres Vornamens ein: ");
      /* 4. Fehler:
         es muss
    
         scanf("%s", your);
    
         sein und your ist zu klein für drei Buchstaben.
         your[4] wäre richtig (3 Buchstaben + Null-Byte)
         -> Speicherzugriffsverletzung / Stack Corruption
      */
      scanf("%s",&your);
      system("cls");
      printf("Geben Sie die ersten 3 Buchstaben des  Namens Ihres Schwarmes ein: ");
    
      /* 5. Fehler:
         es muss
    
         scanf("%s", her);
    
         sein und her ist zu klein für drei Buchstaben.
         her[4] wäre richtig (3 Buchstaben + Null-Byte)
         -> Speicherzugriffsverletzung / Stack Corruption
      */
      scanf("%s",&her);
      system("cls");
    
    
      /* 6. Fehler:
         das Array NaN ist ein Character-Array somit ist
         NaN[zahl1] ein Character. Dieser Charachter wird hier
         als Zeiger interpretiert
         -> Speicherzugriffsverletzung
      */
      for(zahl1=0;zahl1<=2;zahl1++)  {
            if((strcmp(your[zahl1],NaN[zahl1])==0)) your[zahl1] = a;
            /*if((strcmp(your[zahl1],"b")==0)) your[zahl1] = b;
            if((strcmp(your[zahl1],"c")==0)) your[zahl1] = c;
            if((strcmp(your[zahl1],"d")==0)) your[zahl1] = d;
            if((strcmp(your[zahl1],"e")==0)) your[zahl1] = e;
            if((strcmp(your[zahl1],"f")==0)) your[zahl1] = f;
            if((strcmp(your[zahl1],"g")==0)) your[zahl1] = g;
            if((strcmp(your[zahl1],"h")==0)) your[zahl1] = h;
            if((strcmp(your[zahl1],"i")==0)) your[zahl1] = i;
            if((strcmp(your[zahl1],"j")==0)) your[zahl1] = j;
            if((strcmp(your[zahl1],"k")==0)) your[zahl1] = k;
            if((strcmp(your[zahl1],"l")==0)) your[zahl1] = l;
            if((strcmp(your[zahl1],"m")==0)) your[zahl1] = m;
            if((strcmp(your[zahl1],"n")==0)) your[zahl1] = n;
            if((strcmp(your[zahl1],"o")==0)) your[zahl1] = o;
            if((strcmp(your[zahl1],"p")==0)) your[zahl1] = p;
            if((strcmp(your[zahl1],"q")==0)) your[zahl1] = q;
            if((strcmp(your[zahl1],"r")==0)) your[zahl1] = r;
            if((strcmp(your[zahl1],"s")==0)) your[zahl1] = s;
            if((strcmp(your[zahl1],"t")==0)) your[zahl1] = t;
            if((strcmp(your[zahl1],"u")==0)) your[zahl1] = u;
            if((strcmp(your[zahl1],"v")==0)) your[zahl1] = v;
            if((strcmp(your[zahl1],"w")==0)) your[zahl1] = w;
            if((strcmp(your[zahl1],"x")==0)) your[zahl1] = x;
            if((strcmp(your[zahl1],"y")==0)) your[zahl1] = y;
            if((strcmp(your[zahl1],"z")==0)) your[zahl1] = z;*/
            //her
            if((strcmp(her[zahl1],NaN[zahl1])==0)) her[zahl1] = a;
            /*if((strcmp(her[zahl1],"b")==0)) her[zahl1] = b;
            if((strcmp(her[zahl1],"c")==0)) her[zahl1] = c;
            if((strcmp(her[zahl1],"d")==0)) her[zahl1] = d;
            if((strcmp(her[zahl1],"e")==0)) her[zahl1] = e;
            if((strcmp(her[zahl1],"f")==0)) her[zahl1] = f;
            if((strcmp(her[zahl1],"g")==0)) her[zahl1] = g;
            if((strcmp(her[zahl1],"h")==0)) her[zahl1] = h;
            if((strcmp(her[zahl1],"i")==0)) her[zahl1] = i;
            if((strcmp(her[zahl1],"j")==0)) her[zahl1] = j;
            if((strcmp(her[zahl1],"k")==0)) her[zahl1] = k;
            if((strcmp(her[zahl1],"l")==0)) her[zahl1] = l;
            if((strcmp(her[zahl1],"m")==0)) her[zahl1] = m;
            if((strcmp(her[zahl1],"n")==0)) her[zahl1] = n;
            if((strcmp(her[zahl1],"o")==0)) her[zahl1] = o;
            if((strcmp(her[zahl1],"p")==0)) her[zahl1] = p;
            if((strcmp(her[zahl1],"q")==0)) her[zahl1] = q;
            if((strcmp(her[zahl1],"r")==0)) her[zahl1] = r;
            if((strcmp(her[zahl1],"s")==0)) her[zahl1] = s;
            if((strcmp(her[zahl1],"t")==0)) her[zahl1] = t;
            if((strcmp(her[zahl1],"u")==0)) her[zahl1] = u;
            if((strcmp(her[zahl1],"v")==0)) her[zahl1] = v;
            if((strcmp(her[zahl1],"w")==0)) her[zahl1] = w;
            if((strcmp(her[zahl1],"x")==0)) her[zahl1] = x;
            if((strcmp(her[zahl1],"y")==0)) her[zahl1] = y;
            if((strcmp(her[zahl1],"z")==0)) her[zahl1] = z;*/
    
    }
      int res1 = (int)your[0]+(int)your[1]+(int)your[2];
      int res2 = (int)her[0]+(int)her[1]+(int)her[2];
      int res;
      res=res1-res2;
      printf("%d",res);
      system("PAUSE");
      return 0;
    }
    Ich hoffe, das Hilft ein wenig weiter. Da ich jetzt aber auf Anhieb auch nicht sehe, was dabei wirklich rauskommen soll, fällt es mir schwer eine gute Verbesserung abzugeben.
    Der Vollständigkeit halber noch die Ausgabe meines Compilers:
    C:\Users\User\devel\codeblocks\infinity\mathj.c||In function 'fak':|
    C:\Users\User\devel\codeblocks\infinity\mathj.c|11|warning: comparison between pointer and integer|
    C:\Users\User\devel\codeblocks\infinity\mathj.c||In function 'vonbis':|
    C:\Users\User\devel\codeblocks\infinity\mathj.c|53|warning: comparison between pointer and integer|
    C:\Users\User\devel\codeblocks\infinity\mathj.c||In function 'prim':|
    C:\Users\User\devel\codeblocks\infinity\mathj.c|83|warning: control reaches end of non-void function|
    C:\Users\User\devel\codeblocks\infinity\mathj.c||In function 'vonbis':|
    C:\Users\User\devel\codeblocks\infinity\mathj.c|54|warning: control reaches end of non-void function|
    C:\Users\User\devel\codeblocks\infinity\mathj.c||In function 'fak':|
    C:\Users\User\devel\codeblocks\infinity\mathj.c|12|warning: control reaches end of non-void function|
    C:\Users\User\devel\codeblocks\infinity\main.c||In function 'main':|
    C:\Users\User\devel\codeblocks\infinity\main.c|70|warning: format '%s' expects type 'char *', but argument 2 has type 'char * (*)[2]'|
    C:\Users\User\devel\codeblocks\infinity\main.c|83|warning: format '%s' expects type 'char *', but argument 2 has type 'char * (*)[2]'|
    C:\Users\User\devel\codeblocks\infinity\main.c|94|warning: passing argument 2 of 'strcmp' makes pointer from integer without a cast|
    c:\compiler\mingw\bin\..\lib\gcc\mingw32\4.5.2\..\..\..\..\include\string.h|43|note: expected 'const char *' but argument is of type 'char'|
    C:\Users\User\devel\codeblocks\infinity\main.c|94|warning: assignment makes pointer from integer without a cast|
    C:\Users\User\devel\codeblocks\infinity\main.c|121|warning: passing argument 2 of 'strcmp' makes pointer from integer without a cast|
    c:\compiler\mingw\bin\..\lib\gcc\mingw32\4.5.2\..\..\..\..\include\string.h|43|note: expected 'const char *' but argument is of type 'char'|
    C:\Users\User\devel\codeblocks\infinity\main.c|121|warning: assignment makes pointer from integer without a cast|
    ||=== Build finished: 2 errors, 11 warnings ===|

  12. Diskutiere mit und stelle Fragen: Jetzt kostenlos anmelden!

    lima-city: Gratis werbefreier Webspace für deine eigene Homepage

Dir gefällt dieses Thema?

Über lima-city

Login zum Webhosting ohne Werbung!