Solved

delline()function?

Posted on 1997-03-07
5
1,677 Views
Last Modified: 2008-03-04
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
Comment
Question by:kenrick
5 Comments
 
LVL 4

Expert Comment

by:jos010697
Comment Utility
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
 

Author Comment

by:kenrick
Comment Utility
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
 
LVL 4

Expert Comment

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

0
 
LVL 1

Expert Comment

by:Michel021497
Comment Utility
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
 
LVL 1

Accepted Solution

by:
roy020697 earned 50 total points
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now