#include <iostream>
int length(char *str) {
int length = 0;
while (*(str + length) != 0) {
length++;
}
return length;
}
void input(char **array, int rows, int columns) {
for (int i = 0; i < rows; i++) {
*(array + i) = new char[columns];
char* data = new char[columns];
std::cout << "Enter input for the {" << i << "} row\n";
std::cin.ignore();
std::cin.getline(*(array+i), columns);
}
}
void output(char **array, int rows, int columns) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
std::cout << *(*(array + i) + j) << " ";
}
std::cout << std::endl;
}
}
int main() {
int rows = 0;
std::cout << "How many rows does the input contain?";
std::cin >> rows;
int columns = 0;
std::cout << "How many columns does the input contain?";
std::cin >> columns;
char **array = new char *[rows];
input(array, rows, columns);
output(array, rows, columns);
}```
#First character isn't being displayed. (Ptrs and arrays)
22 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
you would do well by replacing this with std::string ngl
data is being useless there.
but most likely there is garbage memory in there somewhere
You issued std::cin.ignore(), which skipped the first character.
You need to learn about the leftover newline in the input buffer, when it's there and when it isn't.
i cannot use strings or any builtin functions. This is a question for an assignment

yep. its a long question :> haven't gotten around to that part yet.
I'll get back to that once my input is correct.
it should be at the end right?
after getline?
It should be between an input that creates a leftover newline and the getline call.
One such input is an integer input.
After you have taken the first row, it's between two getline calls and you must not issue ignore.
Thanks
for the hint
so I'll be adding cin.ignore() after the column input.
Not in the loop
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity