I have written a program that creates a sidescrolling marquee effect, and it works perfectly on my Mac's terminal. However, when I run it on my raspberry pi (Raspbian Linux), the effect messes up and starts printing on a new line and doesn't scroll the full length of text. Can anyone figure out what the issue is? I have tried for days now.
// Compile: gcc marquee.c -o marquee -lncurses
// Usage: ./marquee filename length row col speed
// Reads text from a file and displays 'length' number of chars 
// scrolling sideways at a given 'row, col' position at some indicated 'speed'
#include    <curses.h>
#include    <string.h>
#include    <unistd.h>
#include    <stdio.h>
#include    <stdlib.h> 
#include    <fcntl.h>
#define ROW 10
int main(int ac, char *av[])
{
    if(ac != 6){
        printf("marquee [fileName] [row] [col] [speed (1-99)]\n");
        perror("Insuffecient argument count\n"); 
        exit(1); 
    }
    char message[256];
    int text_length;
    int i;
    int k;  
    int orgPos = atoi(av[4]);
    int pos;
    int row = atoi(av[3]);  
    int dir = 1; 
    int maxPos = atoi(av[2]);
    int speed = atoi(av[5]);
    int filedesc = open(av[1], O_RDONLY); 
    if(filedesc < 0) {
        perror("Could not open file");
        exit(1); 
    } 
    if(speed < 10) 
        speed = 500000; 
    if(speed >= 10 && speed < 20) 
        speed = 250000; 
    if(speed >= 20 && speed < 30) 
        speed = 120000; 
    if(speed >= 30 && speed < 40) 
        speed = 100000; 
    if(speed >= 40 && speed < 60) 
        speed = 80000; 
    if(speed >= 60 && speed < 70) 
        speed = 60000; 
    if(speed >= 70 && speed < 80) 
        speed = 40000; 
    if(speed >= 80 && speed < 90) 
        speed = 20000; 
    if(speed >= 90 && speed < 95) 
        speed = 10000; 
    if(speed >= 95 && speed <= 99) 
        speed = 5000; 
    int bytesRead = 0; 
    while(bytesRead == read(filedesc, message, 256) > 0){
    }
    // Get text length
    text_length = strlen(message);
    initscr(); // initialize curses
    clear();
    curs_set(0);
    while(1) {
        clear(); // clear last drawn iteration
        pos = orgPos;
        char * scroll;
        scroll = malloc(2*maxPos);
        for(i = 0; i<2*maxPos; i++) 
        {
            scroll[i] = message[i%text_length];
        }
        for(i = 0; i < 1000; i++){
                mvaddnstr(row, orgPos, &scroll[i%maxPos], maxPos);
                usleep(speed);
                refresh();
        }
    }
    endwin();
    if(close(filedesc) == -1) 
    {
        perror("Error closing file"); 
        exit(1); 
    }
}
There are surely many improvements to be made here, but please let the aim of your debugging be figuring out why this will not run correctly on linux. Here is a sample test case:
$ ./marquee scroll.txt 25 0 0 50
scroll.txt contains the following:
Hello, this is a test for the scrolling marquee. 
 
    