this program is supposed to output to the console a string of letters i type in, for example if i type in "im hungry" then its supposed to output im hungry to the console in a matrix for, if something i type in is too long then it carries over to the next line of the matrix
heres the code i have so far:
#include <iostream>
#include <string>
using namespace std;
#define N 6
//
// fill:
//
void fill(string s, int M[][N], int ROWS, int COLS)
{
int i, r, c;
s= "x";
for (i=0, r=0; r < ROWS; r++)
{
for (c=0; c < COLS; c++)
{
M[r][c] = s[i]; // store ith character into matrix:
i++; // next character:
if (i == s.length()) // start-over if that was last char:
i = 0;
}
}
}
void print(int M[][N], int ROWS, int COLS)
{
string s;
s= "x";
int r, c;
for(r=0; r< ROWS; r++)
{
for(c=0; c < COLS; c++)
{
cout<<(char)M[r][c];
}
cout <<endl;
}
}
//
// main:
//
int main()
{
string s;
getline(cin,s);
int M[N][N];
int M2[N][N];
int row, col, ROWS, COLS;
fill(s, M, 1, 1);
print(M, ROWS, COLS);
return 0;
}
instead of outputting what I type in, it keeps outputting a matrix of random characters (same no matter what I type in) any suggestions on how I can fix this?