#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Post How to display everything with mvaddch?


    I have a text file that says de3 dn4 dw5 ds8

    the de, dn , dw and ds stand for the position of the door(d), and the number stand for the increment of the cursor...
    i'm using ncurse for this.

    so if the program reads de3, its will post a door to east side at position 3 and so on.

    i am able to get it but can only display the first one which is de3.. how can i display all the other ones at the same time?

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ncurses.h>
    
    #define DOOR '+'
    
    void handleCommand(const char *c,char board[][100]);
    void display ( char board[][100] ) ;
    
    
    void handleCommand(const char *c,char board[][100])
    {
        char  item;
        char  direction;
        int   distance;
        int x = 0, y = 0;
        
        /* analyse for dw3 etc  */
        sscanf(c,"%c%c%d",&item,&direction,&distance);
        initscr();
        if (item == 'd') {
            if (direction == 'e') {
                board[distance-direction][y] = DOOR;
    
            } else if (direction == 'n') {
                board[x][distance-direction] = DOOR;
    
            }else if (direction == 'w') {
                board[x][y-direction] = DOOR;
        
            } else if (direction == 's') {
                board[x][y-direction] = DOOR;
           
            }
            display(board);
         getch();
         endwin();
      }
    }
    void display ( char board[][100] ) {
        initscr();
    
        //mvaddch in a loop to display the board
        
        getch();
        endwin();
        return 0;
        
    }
    
    int main()
    {
        char board[100][100];
        initscr();
        FILE *pFile;
        char command[10];
        
        
        pFile = fopen("room.txt", "r");
        if (pFile == NULL)
            perror("Error opening file");
        else {
            while (fscanf(pFile, "%s", command) == 1) {
                handleCommand(command,board);
            }
          
        }
        fclose(pFile);
        return 0;
    }
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0
    LOL...sorry but i need some answers because i cant figure it out and you were off.

IMN logo majestic logo threadwatch logo seochat tools logo