Need help storing character values into a 2D array

So I am almost finished with this program, and I need to take a set of int values from a previous array, go through each value, determine if the value is >= 128, and if it is then display and astrix ("*"), and if its not display an empty space (" ").

How do I store character values into an array? (Look towards the bottom of my code).

-Thanks everyone

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;

const int rows = 4,
cols = 4;

void displayArray(int a[rows][cols]);

int main()
{
	
	int intImage[rows][cols],
		rc[rows][cols],
		i,
		j;

	char charImage[rows][cols];

	ifstream infile;

	infile.open("TextFile1.txt");	//Importing TExtFile1.txt

	if (!infile)	//Checks whether or not the program can locate the file or not
	{
		cerr << "file could not be found\n";	//Displays an error message
		
		exit(1);	//Ends the program
	}

	cout << "The image before the Roberts Cross operator has been applied to it" << endl;
	cout << endl;

	for (i = 0; i < rows; i++)
	{
		for (j = 0; j < cols; j++)
		{
			infile >> intImage[i][j];
		}
	}

	displayArray(intImage);

	cout << endl;
	cout << "The image after the Roberts Cross operator has been applied to it" << endl;
	cout << endl;

	for (i = 0; i < rows; i++)
	{
		for (j = 0; j < cols; j++)
		{
			rc[i][j] = (abs(intImage[i][j] - intImage[i + 1][j + 1]) , abs(intImage[i + 1][j] - intImage[i][j + 1]) );
		}
	}
	
	displayArray(rc);

	for (i = 0; i < rows; i++)
	{
		for (j = 0; j < cols; j++)
		{
			if (rc[i][j] >= 128)
				
				charImage[i][j] = "*";

			else if (rc[i][j] < 128)
				
				charImage[i][j] = " ";

		}
	}

	return 0;
}

void displayArray(int a[rows][cols])
{
	int i,
		j;
	
	for (i = 0; i < rows; i++)
	{
		for (j = 0; j < cols; j++)
		{
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}
The mistake is probably on lines 68 and 72.

You do
1
2
charImage[i][j] = "*";
charImage[i][j]= " ";


This is a mistake. Double quotes (" ") are used for strings. Single quotes(' ') are used for char

Like this:
1
2
charImage[i][j] = '*';
charImage[i][j]= ' ';

Wow thanks so much! It fixed it!
Topic archived. No new replies allowed.