Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17



Posted on 1997-03-07
Medium Priority
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
        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);

Question by:kenrick
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1249707
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

Author Comment

ID: 1249708
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()


Expert Comment

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


Expert Comment

ID: 1249710
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.

Accepted Solution

roy020697 earned 150 total points
ID: 1249711
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() */

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

704 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