Hi all,
First of all i'd like to say that I'm new to linux (I use Slackware 13) and it's the first time i use the ncurses library.
Concerning my problem, i am trying to make a program with ncurses that prints a labyrinth and user moves a little robot out of it. I have the labyrinth in a txt file called map.txt and i copy this to a 2D 60x20 array called map. I printed the array and seems ok. The problem is that when i am trying to print the array after creating a window (printw("%c",map[i][j]) the cursor moves as if the program has printed the contents but there are only blank chars on the screen.
I read in another thread on this forum (
http://www.linuxquestions.org/questi...-prob.-346656/) that this could be happening because there are \r\n chars in the txt file. But even if that's the problem i don't know how to remove them.
Here is the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ncurses.h>
int main(int argc, char **argv){
FILE *fptr;
char ch,map[62][20],ex;
int i,j;
int X,Y;//column=20; row=8;
int mv;
if( (fptr=fopen("map.txt", "r"))==NULL)
{
printf("map.txt doesn't exist.\n");
exit(1);
}
i=0;
j=0;
while((ch=getc(fptr))!= EOF){
map[i][j]=ch;
j++;
if(j>19){
i++;
j=0;}
}
fclose(fptr);
for(i=0;i<62;i++)
for(j=0;j<20;j++)
printf("%c",map[i][j]);
if(initscr()==NULL)
printf("Error initializing ncurses!\n");
cbreak();
noecho();
keypad(stdscr,TRUE);
do{
for(i=0;i<62;i++)
for(j=0;j<20;j++)
printw("%c",map[i][j]);
/*j++;
if(j>19)
i++;j=0;}*/
refresh();
ex=getch();}
while (ex!='q');
endwin();
return 0;
}
And here is the labyrinth that i'm trying to print on the window:
Code:
************************************************************
* *
* ********* **** ************ ****************** ********* *
* ********* **** ************ * ********* ********* *
* ********* **** ************ * ****** ********* ********* *
* ********* **** * * ********* ********* *
* ********* ***************** ******** ********* ********* *
* * * *
* ******************* * *** * **************************** *
* ******************* * *** * **************************** *
* ******************* * *** * ** ** *
* ******************* * *** * ************ *************** *
* ********* * * ************ ***** *
* **** **** ********* ******* ************ ***** **** **** *
* **** **** ********* ************ ***** **** **** *
* ****************************** ***** **** **** *
* **** **** * * **** ** *
* **** **** ***************** ****************** ********* *
* E
************************************************************
Any help or idea appreciated. Thank you!
PS:It's actually somewhat urgent(!!). School project. I'd be grateful if anyone could help!