Hi! I am trying to get a grip on arrays, and I have a project that I need to complete.
I need to put user input into arrays. I have tried on my own, as well as looking up many forums from this site and others. I have read a lot about using pointers, and that seems to be the ideal way, but I have been instructed to only use arrays and functions.
This is one question I must ask. And currently I am getting a runtime error #2, with variable s.
Here is what I have:
#include <iostream>
using namespace std;
int main ()
{
You don't want to cin >> s[9]; because what you're really doing is inputting one int at index 9, or the 10th spot, which is out of range (when creating an array int s[9]; you're creating an array of ints that take up 9 memory chunks. 0-8 contain the information, while 9 is out of range, and more than likely running into some other unknown data for your program.) Instead, what you would do, is cin >> s[0]; but this won't work like you think it will. To input each of the 9 positions, you would need to use a for loop and increment the index. Also, an integer that is 9 numbers long (one hundred million or larger) will still only take up one spot in the array.
In order to do what I believe you want to do, is use a character array. Each number typed from the keyboard will be set into the array. This is also referred to a C-style string (the C++ strings work on a similar level, but much more effective).
A sample of what you want to do would be something like:
1 2 3 4 5 6 7 8 9 10 11 12 13
char ssid[9];
std::cout << "Please enter the SSID: ";
// This will store each character entered into each index of the array
std::cin >> ssid;
// Print out the SSID
for (int i = 0; i < 9; i ++)
// This will display each character on it's own line
std::cout << ssid[i] << "\n";
// Or an easier way
// This will display the entire character array (C string)
std::cout << ssid;