Click to See Complete Forum and Search --> : Help with KDevelop please...


MkIII_Supra
10-31-2001, 01:22 AM
I am using KDevelop to build this simple program for my software testing class. But the make option or build options are not active. I tried to go my command line and use g++ but I got the following error:


MkIII Supra: g++ exer3.cpp
exer3.cpp:9:19: conio.h: No such file or directory
exer3.cpp:40:1: warning: no newline at end of file


So any suggestions from the KDevelop gurus? I haven't really had much time to play with it yet so my C/C++ is rusty and trying to learn a new IDE on top of refreshing my C/C++ skills... anyhow thanks in advance!


/************************************************** **************
Author Name: Mac McDonald
Program Name: exer3.cpp
Statement of purpose: Request three numbers, read them in
Display the numbers, the total and average
************************************************** ***************/
/* Header file(s)) for this program */
#include <stdio.h>
#include <conio.h>

/* Start main function */
main(){
int nbr1, nbr2, nbr3, total, average;

/* initialize total to zero */
total = 0;

/* Get each number from the user and add it to the running total */
printf("\nEnter the first number followed by the enter key : ");
scanf("%d", &nbr1);
total = total + nbr1;

printf("\nEnter the second number followed by the enter key : ");
scanf("%d", &nbr2);
total = total + nbr2;

printf("\nEnter the third number followed by the enter key : ");
scanf("%d", &nbr3);
total = total + nbr3;

/* Compute the average */
average = total / 3;

/* Print the numbers */
printf("\n\nThe numbers you entered, total and average are: ");
printf("\n\nnbr1 is %d, nbr2 is %d, nbr3 is %d" , nbr1, nbr2, nbr3);
printf("\nThe total is %d\nThe average is %d" , total, average);
getch();
return 0;
}

[ 31 October 2001: Message edited by: MkIII_Supra ]

[ 31 October 2001: Message edited by: MkIII_Supra ]

Pinball
10-31-2001, 07:52 AM
conio.h is not available under linux, at least not that I know, you could use getchar() in stead of getch, the user should press enter in stead of any key.
If you really want to have any key pressed http://www.codeexamples.org/
has a good example of how to do it...

JasonC
10-31-2001, 01:42 PM
I think he is right. conio.h is actually a borland header I believe. You could also just use a scanf at the end.

Stuka
10-31-2001, 05:40 PM
MkIII - is this a DOS/Win file you're opening in Linux? That might explain the "no newline" bit - although it should be putting in extra control characters if ya ask me...and like they saic, <conio.h> ain't available in Penguin land - unless someone ports it! ;)

debiandude
10-31-2001, 06:10 PM
I wrote a getch function. So here this code will compile:

#include <stdio.h>
#include <termios.h>

/* Here is my version of the getch function */
int getch(void);


/* Start main function */
main(){
int nbr1, nbr2, nbr3, total, average;

/* initialize total to zero */
total = 0;

/* Get each number from the user and add it to the running total */
printf("\nEnter the first number followed by the enter key : ");
scanf("%d", &nbr1);
total = total + nbr1;

printf("\nEnter the second number followed by the enter key : ");
scanf("%d", &nbr2);
total = total + nbr2;

printf("\nEnter the third number followed by the enter key : ");
scanf("%d", &nbr3);
total = total + nbr3;

/* Compute the average */
average = total / 3;

/* Print the numbers */
printf("\n\nThe numbers you entered, total and average are: ");
printf("\n\nnbr1 is %d, nbr2 is %d, nbr3 is %d" , nbr1, nbr2, nbr3);
printf("\nThe total is %d\nThe average is %d" , total, average);
getch();
return 0;
}

int getch(void) {

struct termios term, original;
char c;

if(tcgetattr(fileno(stdin), &term) < 0) {
perror("Error getting terminal information");
return -1;
}

original = term;

term.c_lflag &= ~ICANON;
term.c_lflag &= ~ECHO;
term.c_cc[VMIN]=1;
term.c_cc[VTIME]=0;

if(tcsetattr(fileno(stdin), TCSANOW, &term) < 0) {
perror("Error setting terminal information");
return -1;
}

getc(stdin);

if(tcsetattr(fileno(stdin), TCSANOW, &original) < 0) {
perror("Error setting terminal information");
return -1;
}

return c;

}


[ 31 October 2001: Message edited by: debiandude ]