Hello everyone,

I am having a problem with a function I am working on. It has to do the following:

Outputs the null-terminated string pointed to by s starting at row row and column column, in a field of length characters. As with dtioCursor(), the row value 0 refers to the top row, and the column value 0 refers to the left-most column. If the string is longer than length, your function only displays the first length characters. If the string is shorter than length, your function displays the entire string, followed by enough trailing spaces to fill out the field. However, if length is 0 or less, your function displays the entire string with no trailing spaces. After displaying s, your function positions the cursor after the last character displayed including any displayed trailing spaces. Your function does not flush the output buffer. The results are undefined if the string does not fit on the screen.

The code of what I have so far for it is bellow, when I try to compile it on the Borland platform I get 2 warnings about maloc with no prototype in the function and then an error that says "Unresolved external '_maloc' referenced from C:\Users\... and so on. I also get a warning about comparing signed and unsigned values.

void dtioDisplay(const char *s, int row, int column, int length){
     char * oput;
     char * pput;
     char c;
     int lval, i, cloc;
     
     pput = (char *) maloc(c * (strlen(s) + 1));
     strcpy(pput, s);
     
     dtioCursor(row, column);
     
     if(length > 0){
         cloc = column + length;
         oput = (char *) maloc(c * (length + 1));
         lval = strlen(s);
         lval -= length;
         if(lval < 0){
             for(i = 0; i < strlen(s); i++)   
                 oput[i] = pput[i];
             do{
                 oput[i] = ' ';
                 lval++;
                 i++;
             }while(lval < 0);
             oput[i] = '\0';
         }
         else if(lval > 0){
             for(i = 0; i < length; i++)
                oput[i] = pput[i];
             oput[i] = '\0';
         }
         else{
             strcpy(oput, pput);
         }
         
         dtioPuts(oput);
         free(oput);
     }
     else{
        cloc = column + strlen(pput);
        dtioPuts(pput);
     }
     
     dtioCursor(row, cloc);
     free(pput); 
 }

This is the dtioCursor function used.

void dtioCursor(int row, int column) {
     #if PLATFORM == BORLANDC
     gotoxy(column + 1, row + 1);
     #elif PLATFORM == VSNETC
     HANDLE hStdout;
     struct _CONSOLE_SCREEN_BUFFER_INFO x;
     hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
     GetConsoleScreenBufferInfo(hStdout, &x);
     x.dwCursorPosition.X = column;
     x.dwCursorPosition.Y = row;
     SetConsoleCursorPosition(hStdout, x.dwCursorPosition);
     #elif PLATFORM == GCC
     move(row, column);
     #endif
 }

This is the dtioPuts function used in the above program.

void dtioPuts(const char* s) {
     #if PLATFORM == BORLANDC || PLATFORM == VSNETC
     cputs(s);
     #elif PLATFORM == GCC
     addstr(s);
     #endif
 }

I am not sure on what I am doing wrong here.

Recommended Answers

All 2 Replies

The function is malloc() , not maloc().

Oh wow! Thanks a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.