Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1793
  • Last Modified:

delline()function?

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
average.
        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
kenrick@myhost.com

thanks
still learning
Edward

#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]);
                delline();
                printf("\n");
                printf("\tGrade # %2i is \t%.2f\n", i, grades[i]);
                sum = sum + grades[i];
        }
                printf("\n");
                printf("\tThe total average of the %i grades is %.2f",
                                  num_grades, sum/num_grades);
}

0
kenrick
Asked:
kenrick
1 Solution
 
jos010697Commented:
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
(because
0
 
kenrickAuthor Commented:
My error messages are
Compiling DELETELN.CPP:
Error DELETELN.CPP 29: Call to undefined function 'delline' in function main()
Error DELETELN.CPP 29: Expression syntax in function main()

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

0
 
Michel021497Commented:
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.
0
 
roy020697Commented:
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() */
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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