• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1831
  • Last Modified:


Experienced ‘C’ programmers:
                                            I’m experimenting with a
beginners exercise program.  The program prompts me to read-in a # of
scores to an array.  It next prints out the grade location, and the
grade.  The last thing it does is print out the overall grade average.  
        What I’m trying to do is clear my prompts from my output window using
the delline function.  I’d like to have a nice clean output window with
only the grade locations, and the grades,  and lastly the overall grade
        I know I can do this by printing to a file, but I’m really trying to
find out how the delline function works.  I’ve enclosed my sample
program, which won’t compile with the delline function in line #29.  The
program works with prompts, when line #29 is remarked.  

Please respond by e-mail

still learning

#include <stdio.h>
#include <conio.h>

void main ()
/* declarations */

        int i, num_grades;
        float grades[50], sum = 0;

/* input */

        printf("Enter the number of grades you want to average...");
        scanf("%i", &num_grades);

/* processing */

        for(i = 1; i <= num_grades; ++i)
                printf("\t\nEnter a grade...\r\n");
                scanf("%f", &grades[i]);
                printf("\tGrade # %2i is \t%.2f\n", i, grades[i]);
                sum = sum + grades[i];
                printf("\tThe total average of the %i grades is %.2f",
                                  num_grades, sum/num_grades);

1 Solution
Your compiler cannot protest against that delline() function;
it's just a function (possibly not previously declared, but
that's it). Does your linker complain? Something like
'unresolved symbol _delline'? If so, check your manuals
for the right library to link with your program.

BTW. If delline clears the current line, your program is
still not going to work properly, , because the delline()
function will clear the line following the prompt line and
the input line (because of the '\r\n' pair output in the
prompt and the <enter> key pressed by the user).

kind regards,

Jos aka jos@and.nl
kenrickAuthor Commented:
My error messages are
Error DELETELN.CPP 29: Call to undefined function 'delline' in function main()
Error DELETELN.CPP 29: Expression syntax in function main()

Does 'conio.h' contain a declaration of the delline()
function? If not, C++ complains about it (C wouldn't, really)

You could try renaming DELETE.CPP to DELETE.C
I suppose you use the Borland C compiler.
When using .CPP files, the compiler assumes it is a C++ file.
When using .C files, the compiler assumes it is a C file.
I'm not sure how delline() is implemented by your compiler; it is not an ANSI or POSIX function. By the looks of your error messages it seems as though your compiler can't find a function named delline() to link with.  Here is a delline function which will work for you. Just copy these lines before your main() function. It will print out a bunch of backspace characters, then a bunch of whitespace, then a bunch of backspace characters again. Not very elegant, but should be platform independant. A more elegant solution would use the termcap entry definition (in UNIX) to know which byte sequence would to the same thing with less bytes output. On a PC this would be the same as the BIOS supported escape sequences... anyway, here's the code:

#define MAX_LINE_LENGTH    79    /* adjust to suit needs */
** This function does not use terminal based escape sequences to
** delete characters on a line; it uses ANSI supported escape sequences
** as supported by the printf() function to achiieve this goal.
void delline()
   int i;       /* index of for loops */

   for( i=0; i<MAX_LINE_LENGTH; i++ )
      printf( "\b" );      /* print out the backspace character  */
   for( i=0; i<MAX_LINE_LENGTH; i++ )
      printf( "%c", 0x20 );    /* print out the space character to clear text */
   for( i=0; i<MAX_LINE_LENGTH; i++ )
      printf( "\b" );  /* backspace again to put the cursor at  start of a line */
} /* end functiuon delline() */
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now