The function is supposed to take an output file from the command line input. The function is supposed to output and array of strings one character at a time vertically into the file:
ex:
h
e
l
l
o
...
This code has a lot of problems, I've read the chapter on arrays twice in my book, and I'm still struggling. If anyone could help me solve the many problems with this code, by offering revisions, and common array knowledge/rules that would be helpful.
You are not creating an array of C-style strings, char array. You are creating a 2 dimensional array of C++ std strings. Not what you want.
Trying to write data into your executable file is going to fail, period. argv[0] is the name of your program's .exe file. If you are supplying an output file name via the command line you should use argv[1].
The function "verticalWords" at the bottom doesn't have the same parameters as the one declared ontop, so they are NOT considered to be the same function. Your compiler may complain that "verticalWords" has no definition.
Also, if all you need to do is simply output words vertically into a file, you only need a simple array of strings.
Consider:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int main()
{
std::ofstream outFile;
outFile.open("Whatever.txt");
constint strL = 3; //How Many Words/Phrases In String
std::string words[strL] = { "Hello", "abc", "I'm Highly Depressed" };
for (int count = 0; count < strL; count++) //Go Through Each Word
{
for (int i = 0; i < words[count].length(); i++) //Go Through Each Letter
{
outFile << words[count][i] << '\n';
}
outFile << '\n';
}
}
Normally, to go through every letter in the string you do something like string[i] . When you want to do that with an array of strings, that first [] should instead indicate which word in the string you want to access and another [] with the letter you want to access within that word.
For example, if I want the 3rd letter of the 2nd word in a string array, I'd do this:
1 2 3
std::string word[5] //String With 5 Words
//Give The String Some Values
std::cout << word[1][2]; // 1 and 2 Since When Accessing An Array, You Start At 0