I'm trying to read a keyboard entry into a 256 char buffer then extract from just the chars entered (trying to restrict it to just 8 characters) I am fundamentally not understanding how the #$%#$^ing char arrays work:
#include <iostream>
using namespace std;
int main()
{
char buffer[256];
char pw[8];
int counter = 0;
cin >> buffer;
for(int i = 0; i < 256; i++)
{
if(buffer[counter] == '\n')
{
break;
}
else
{
counter++;
}
}
if(counter > 8)
{
cout << "too large\n";
cout << endl<<counter;
}
else
{
for(int i = 0; i < 8; i++)
{
pw[i] = buffer[i];
}
cout << "\nPassword "<< pw;
}
}
Instead of the while stopping at 8 it just goes whole Fing hog. Can someone tell me what's going on?