Ignoring spaces when using scanf in c++

I’ve been trying to solve this problem:

My issue is that when I scanf through the cowsignal, the whitespace messes up my looping
Here is my code so far:

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
  freopen("cowsignal.in", "r", stdin);
  int m, n, k;
  scanf("%d %d %d", &m, &n, &k);
  char signal[m][n];
  for(int i = 0; i < m; i++) {
    for(int j = 0; j < n; j++) {
      scanf("%c", &signal[i][j]);
      cout << signal[i][j];

Here is output:
Basically the problem is that scanf counts the spaces at the end of each line as a character, messing up my inner for loops j iteration.
I need help with getting scanf to skip the spaces, thanks!.