LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-25-2009, 11:50 AM   #1
cast_kostas
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Rep: Reputation: 0
C (ncurses) printing blank characters


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!
 
Old 10-25-2009, 02:30 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
You probably want to look at the dos2unix utility.
 
Old 10-25-2009, 08:31 PM   #3
cast_kostas
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rjlee View Post
You probably want to look at the dos2unix utility.
Hmm, what am i supposed to do with that? I don't really know how it works (after googling a bit i found out it's called fromdos on Slackware. I made a new file on linux copying the labyrinth there..But i got the same result..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
weird characters appear in a remote (ssh) ncurses 'make menuconfig' nass Slackware 1 10-11-2009 04:47 AM
[SOLVED] blank screen with strange characters while typing after fedora loading bar th3flyboy Linux - Newbie 1 09-02-2009 01:37 AM
ncurses printing character array prob. slzckboy Programming 3 07-31-2005 08:51 AM
few characters like 'i' not printing somasekhar Linux - Newbie 2 12-17-2004 10:25 AM
printing japanese characters... tw001_tw Linux - Software 0 05-02-2004 10:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration