While-Schleife nicht zu sehen, oder die Suche nach abschließenden null-Zeichens

Ich versuche, Durchlaufen ein char-array mit Hilfe einer while-Schleife mit '\0' als abschließende Bedingung, aber mein problem ist, dass Sie nicht finden, die '\0' bis der index-position 481, das array ist deklariert als 200 lange und ich kann nicht sehen, was ich falsch mache!! Ich kann nicht verwenden, Zeichenfolgen oder jegliche form von string-Funktionen für diese, bevor jemand fragt. Kann mir jemand helfen????

#include <iostream>

using namespace std;

int main()
{


char fullString[200]={'\0'}; //Declare char string of 200, containing null characters
int alphaCount = 0;
int charCount = 0;
int wordCount = 0;

cin.getline(fullString,200); //
cout << "\n\n" << fullString;
cout << "\n\n\n";

int i=0;
int i2 = 0;
while(fullString[i]!='\0'){ //iterate through array until NULL character is found

    cout << "\n\nIndex pos : " << fullString[i]; //Output char at 'i' position


   while(fullString[i2]!= ' '){ //while 'i' is not equal to SPACE, iterate4 through array

        if(isalpha(fullString[i2])){

            alphaCount++; //count if alpha character at 'i'
        }
        charCount++; //count all chars at 'i'
        i2++;
    }

    if(charCount == alphaCount){ //if charCount and alphaCount are equal, word is valid

        wordCount++;
    }
   charCount = 0; //zero charCount and alphaCount
   alphaCount = 0;

   i=i2;//Assign the position of 'i2' to 'i'
   while(fullString[i] == 32){ //if spaces are present, iterate past them

        i++;
        cout << "\n\ntest1";

   }
    i2 = i; //assign value of 'i' to 'i2' which is the next position of a character in the array

    if(fullString[i] == '\0')
    {
        cout << "\n\nNull Character " << endl;
        cout << "found at pos: " << i << endl;
    }

}

cout << "\n\ni" << i;
cout << "\n\nWord" << wordCount;

return 0;

}

Schreibe einen Kommentar