plötzliches neustarten des programmes



  • hiu leute

    ich habe folgendes problem :

    wenn ich follgende programmzeilen in mein programm schreibe, startet es neu wenn es zu diesen zeilen kommt. diese sind:

    for(i=0;i<101;i++)
    {
    	if(cText[i][1]==' ')
    	{
    		if(cText[i][0]=='0') r1=0;
    		if(cText[i][0]=='1') r1=1;
    		if(cText[i][0]=='2') r1=2;
    		if(cText[i][0]=='3') r1=3;
    		if(cText[i][0]=='4') r1=4;	
    		if(cText[i][0]=='5') r1=5;
    		if(cText[i][0]=='6') r1=6;
    		if(cText[i][0]=='7') r1=7;
    		if(cText[i][0]=='8') r1=8;
    		if(cText[i][0]=='9') r1=9;
    		rg=r1;
    		ordnung[i]=rg;
    
    	}
    	else if(cText[i][2]==' ')
    	{
    		if(cText[i][0]=='0') r2=0;
    		if(cText[i][0]=='1') r2=1;
    		if(cText[i][0]=='2') r2=2;
    		if(cText[i][0]=='3') r2=3;
    		if(cText[i][0]=='4') r2=4;
    		if(cText[i][0]=='5') r2=5;
    		if(cText[i][0]=='6') r2=6;
    		if(cText[i][0]=='7') r2=7;
    		if(cText[i][0]=='8') r2=8;
    		if(cText[i][0]=='9') r2=9;
    
    		if(cText[i][1]=='0') r1=0;
    		if(cText[i][1]=='1') r1=1;	
    		if(cText[i][1]=='2') r1=2;
    		if(cText[i][1]=='3') r1=3;
    		if(cText[i][1]=='4') r1=4;
    		if(cText[i][1]=='5') r1=5;
    		if(cText[i][1]=='6') r1=6;
    		if(cText[i][1]=='7') r1=7;
    		if(cText[i][1]=='8') r1=8;
    		if(cText[i][1]=='9') r1=9;
    
    		rg=r1+r2*10;
    		ordnung[i]=rg;
    
    	}
    	else if(cText[i][3]==' ')
    	{
    		if(cText[i][0]=='0') r2=0;
    		if(cText[i][0]=='0') r3=0;
    		if(cText[i][0]=='1') r3=1;
    		if(cText[i][0]=='2') r3=2;
    		if(cText[i][0]=='3') r3=3;
    		if(cText[i][0]=='4') r3=4;
    		if(cText[i][0]=='5') r3=5;
    		if(cText[i][0]=='6') r3=6;
    		if(cText[i][0]=='7') r3=7;
    		if(cText[i][0]=='8') r3=8;
    		if(cText[i][0]=='9') r3=9;
    
    		if(cText[i][1]=='0') r2=0;
    		if(cText[i][1]=='1') r2=1;
    		if(cText[i][1]=='2') r2=2;
    		if(cText[i][1]=='3') r2=3;
    		if(cText[i][1]=='4') r2=4;
    		if(cText[i][1]=='5') r2=5;
    		if(cText[i][1]=='6') r2=6;
    		if(cText[i][1]=='7') r2=7;
    		if(cText[i][1]=='8') r2=8;
    		if(cText[i][1]=='9') r2=9;
    
    		if(cText[i][2]=='0') r1=0;
    		if(cText[i][2]=='1') r1=1;
    		if(cText[i][2]=='2') r1=2;
    		if(cText[i][2]=='3') r1=3;
    		if(cText[i][2]=='4') r1=4;
    		if(cText[i][2]=='5') r1=5;
    		if(cText[i][2]=='6') r1=6;
    		if(cText[i][2]=='7') r1=7;
    		if(cText[i][2]=='8') r1=8;
    		if(cText[i][2]=='9') r1=9;
    		rg=r1+r2*10+r3*100;
    		ordnung[i]=rg;
    
    	}
    	else if(cText[i][4]==' ')
    	{
    		if(cText[i][0]=='0') r3=0;
    		if(cText[i][0]=='1') r4=1;	
    		if(cText[i][0]=='2') r4=2;
    		if(cText[i][0]=='3') r4=3;
    		if(cText[i][0]=='4') r4=4;
    		if(cText[i][0]=='5') r4=5;
    		if(cText[i][0]=='6') r4=6;
    		if(cText[i][0]=='7') r4=7;
    		if(cText[i][0]=='8') r4=8;
    		if(cText[i][0]=='9') r4=9;
    
    		if(cText[i][1]=='0') r3=0;
    		if(cText[i][1]=='1') r3=1;
    		if(cText[i][1]=='2') r3=2;	
    		if(cText[i][1]=='3') r3=3;
    		if(cText[i][1]=='4') r3=4;
    		if(cText[i][1]=='5') r3=5;
    		if(cText[i][1]=='6') r3=6;
    		if(cText[i][1]=='7') r3=7;
    		if(cText[i][1]=='8') r3=8;
    		if(cText[i][1]=='9') r3=9;
    
    		if(cText[i][2]=='0') r2=0;
    		if(cText[i][2]=='1') r2=1;
    		if(cText[i][2]=='2') r2=2;
    		if(cText[i][2]=='3') r2=3;
    		if(cText[i][2]=='4') r2=4;
    		if(cText[i][2]=='5') r2=5;
    		if(cText[i][2]=='6') r2=6;
    		if(cText[i][2]=='7') r2=7;
    		if(cText[i][2]=='8') r2=8;
    		if(cText[i][2]=='9') r2=9;
    
    		if(cText[i][3]=='0') r1=0;
    		if(cText[i][3]=='1') r1=1;
    		if(cText[i][3]=='2') r1=2;
    		if(cText[i][3]=='3') r1=3;
    		if(cText[i][3]=='4') r1=4;
    		if(cText[i][3]=='5') r1=5;
    		if(cText[i][3]=='6') r1=6;
    		if(cText[i][3]=='7') r1=7;
    		if(cText[i][3]=='8') r1=8;
    		if(cText[i][3]=='9') r1=9;
    
    		rg=r1+r2*10+r3*100+r4*1000;
    		ordnung[i]=rg;
    
    	}	
    
    }
    

    worann kann das leigen? ist vieleicht mein gesamtes programm schon zu lange für TC???



  • zu lang gibt's nicht. das problem wird wohl die deklaration/initialisierung deines arrays sein.

    und mal so als tip:

    if(cText[i][0]=='0') r1=0;
    if(cText[i][0]=='1') r1=1;
    if(cText[i][0]=='2') r1=2;
    if(cText[i][0]=='3') r1=3;
    if(cText[i][0]=='4') r1=4;   
    if(cText[i][0]=='5') r1=5;
    if(cText[i][0]=='6') r1=6;
    if(cText[i][0]=='7') r1=7;
    if(cText[i][0]=='8') r1=8;
    if(cText[i][0]=='9') r1=9;
    

    kann man hübsch zu r1 = cText[i][0] - '0'; verkürzen (da du ja sowieso nicht berücksichtigst, ob da vielleicht noch ein anderes zeichen stehen könnte). ganz abgesehen davon, dass du auch einfach atoi() nehmen könntest.

    ru,
    cirion



  • eigentlich möchte ich nur das array cText[100][100] , welches ein char ist , so auslesen, dass rg bzw ordnung[i](sind int) eine rechenbare zahl ergeben
    es ist eine liste:

    4



  • 4 mathias
    7 lukas
    9 klaus

    die ich dann nach den zahlen ordnen möchte..



  • wenn cText als [100][100]-array deklariert ist, kannst du nicht bis 100 zählen ( i < 101 ) - der letzte gültige index ist 99.

    anyway. das geht alles viel kürzer:

    #include <stdlib.h>
    [...]
    for (i = 0; i < 100; ++i) 
        ordnung[i] = atoi(&cText[i][0]);
    

    (sofern wirklich alle 100 cText[]-strings mit zahlen beginnen - wenn nicht muss man diese fälle halt noch abfangen).

    ru,
    cirion



  • bewertet atoi nur die erste ziffer, oder alle, solange nur zahlen kommen( dass es praktisch bei : 567 sdfg 567 speichert)??



  • atoi() ignoriert alle führenden whitespaces, parsed die dann folgenden ziffern als integer-wert in dezimaldarstellung, und ignoriert alles ab der ersten nicht-ziffer danach.

    ru,
    cirion



  • DANKE!!!!"
    du hast mir SEHR SEHR SEHR geholfen 😃 👍 👍 😋


Anmelden zum Antworten