Starry Window

Hello everybody, I am making a program where words on individual lines are read from a .txt file and displayed with a star(*) border.
EXAPLE:
WORD: SHORT

* S H O R T *
T * * * * * S
R * * * * * H
O * * * * * O
H * * * * * R
S * * * * * T
* T R O H S *


I have written code for only the first line (i.e.
* S H O R T * 
) but I get a an error while trying to compile, saying: invalid conversion from 'const char*' to 'char'. Please help me out!

Here is my program (any changes or improvements are welcome and appreciated):
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
#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main()
{
    char line[5][20];
    
    
    ifstream file;
    file.open ("DATA11.txt", ios::in);
    if (file.good())
    {
                    while(!file.eof()){
                                       for(int i=0;i<5;i++)
                                       {
                                               file >> line[i];
                                               cout<<line[i]<<endl;                             
                                       }
                                       }
                                       file.close();
    }
                                 
    else cout<<"Unable to Open File";
    
    system("cls");
    
    int length[5];
    for(int L=0;L<5;L++)
    length[L] = strlen(line[L]);
    
      for(int k=0; k<5; k++)
     {
             char star[length[k]][length[k]];
             
             for(int r=0;r<length[k]+2; r++)
             for(int c=0;c<length[k]+2; c++)
             star[r][c] = "*";
             
             for(int a=0; a<length[k]; a++)
             for(int b=0; b<length[k]; b++)
             cout<<length[a][b];
     }
     
    system("pause");
    return 0;
}

Was the error on line 39? Change the "*" to '*'.

"*" represents a string of characters, but you want '*', which represents a single character
Thank you so much! I had completely missed that. But I seem to have a problem with displaying the array from lines 41-43 and I get an error on line 43 saying:
invalid types 'int[int]' for array subscript
.

But if I actually write out the statement, for example, cout<<star[1][1];, then I get output with a line of stars. But the loop doesn't seem to be working. Once again, your help is greatly appreciated!
Last edited on
on line 43, it says cout << length[a][b]. I think you meant cout << star[a][b]
Topic archived. No new replies allowed.