• C


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);

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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() */

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.