#include <iostream>
#include <cstring>
using namespace std;
void getInput(char *password, int length)
{
cout << "Enter password: ";
cin >> *password;
}
int countCharacters(char* password)
{
int index = 0;
while (password[index] != "\0")
{
index++;
}
return index;
}
int main()
{
char password[];
getInput(password,7);
cout << password;
return 0;
}
やあ!ここで、atm で実行できない 2 つのことを試しています。main で長さが指定されていない char 配列を作成しようとしており、関数 countCharacters で char 配列の単語数をカウントしようとしています。しかし、パスワード [インデックス] は機能しません。
編集:宿題をしているので、cstringsのみを使用する必要があります。EDIT2: また、「strlen」関数の使用も許可されていません。