Computing.Net > Forums > Linux > Running c program in linux

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Running c program in linux

Reply to Message Icon

Name: sukhminder
Date: May 5, 2004 at 18:47:52 Pacific
OS: NT
CPU/Ram: P4/128
Comment:

i have to run a c program in linux but there's a getche() which i used in c program. how can i get rid of this getche() in order to run the c code in Linux.

{
/*some code*/
choice=getche();
}while((choice != 'q'));



Sponsored Link
Ads by Google

Response Number 1
Name: Wolfbone
Date: May 5, 2004 at 22:46:26 Pacific
Reply:

info getchar



0

Response Number 2
Name: sukhminder
Date: May 6, 2004 at 19:57:13 Pacific
Reply:

yea i have tried that but its not giving the output which i wanted....This is the actual code ...can u plz run it in C on windows...i want the exact output in Linux as well...the code is as follows:-
/*This program deals with CAI (Computer Aided Instruction) which is often used to both develop and consolidate skills. This programming exercise involves the presentation of arithmetic questions to the user and provides varied feedback. The user h
ave the option to choose a range of numbers to be used in the calculations; for example: single digit numbers or numbers up to 20.

*/
/*Author: Sukhminder Singh*/
/*Ver: cp728-1.0*/
/*Student ID: 2450362*/
#include<stdio.h>

void getGrade(char);
main()
{
/*declarations*/
int i,x,j,k,min,max,option,grade=0,total=0,totalques,range,true=0,false=0,reply,reply1;
int choice1;
char choice;
clrscr();
printf("******************************************************************************");
printf("\n******************************************************************************");
printf("\n======================CHECK YOUR MATHEMATICAL SKILLS==========================");
printf("\n******************************************************************************");
printf("\n******************************************************************************");
printf("\n\nPLEASE ENTER A RANGE OF NUMBERS TO BE USED IN CALCULATIONS:");/*prompting the user for Range*/
printf("\nPlease Enter from -50 to +50:\n");
min=-51;
do/*First do while*/
{
do
{
printf("From What Number:");scanf("%d",&min);/*inputting minimum range*/
}while(min<-50);/*end of min do-while*/
max=51;
do
{
printf("Till What Number Please...");scanf("%d",&max);/*inputting maximum range*/
}while(max>50);/*end of max do-while*/
}while(max<=min);/*end of First do-while*/
range=max-min+1;
do/*main do-while loop*/
{

x=rand() %10;/*using random function to randomise the switch case choices*/
clrscr();
switch (x)/*start of switch case*/
{
case 0:
case 1:
case 2:
case 3: j=random(range)+min;/*calculating the random value for inputing to the question*/
k=random(range)+min;
printf("\n\tWhat is %d times %d ? ",j,k);
scanf("%d",&reply);/*asking for the user reply*/
if(reply == (j*k))/*comparing the value of reply from user with the actual answer*/
{
true++;/*incrementing the value if true*/
getGrade('t');/*calling function for Display Prompts*/
}
else
{
false++;/*incremeting the variable if user reply is false*/
getGrade('f');/*calling the function for Display Prompts*/
}
total++;/*keeping record of the total questions asked*/
break;/*breaking out of the case*/
case 4:
case 5:
case 6: j=random(range)+min;
k=random(range)+min;
printf("\n\tWhat is %d plus %d ? ",j,k);
scanf("%d",&reply);
if(reply == (j+k))
{
true++;
getGrade('t');
}
else
{
false++;
getGrade('f');
}
total++;
break;
case 7:
case 8:
case 9: j=random(range)+min;
k=random(range)+min;
printf("\n\tWhat is %d minus %d ? ",j,k);
scanf("%d",&reply);
if(reply == (j-k))
{
true++;
getGrade('t');
}


else
{
false++;
getGrade('f');
}
total++;
break;
case 10:
case 11:
case 12: j=random(range)+min;
k=random(range)+min;
printf("\n\tWhat is %d divided by %d ?",j,k);
scanf("%d",&reply);
if(reply ==(j/k))
{
true++;
getGrade('t');
}
else
{
false++;
getGrade('f');
}
total++;
break;
}/*end of switch-case*/
printf("\n\t\tThe Number of Correct Answers so far is %d",true);/*Displaying the no of True Answers*/
printf("\n\t\tThe Number of Incorrect Answers so far is %d",false);/*Displaying the no of Flase Answers*/
printf("\n\t\tTotal questions asked %d",total);/*Displaying the number of Total Questions asked*/
printf("\n\nPress q to quit or any other key to continue....\n");
choice=getche();

}while((choice != 'q'));/*end of first do-while*/

grade = ((float)true / total * 100);/*Calculating the Grade according to the Correct Answers from Total*/

if(grade>=80)/*Start of If Condition*/
printf("\n\t\tYour Grade is: A");
else if(grade>=70)
printf("\n\t\tYour Grade is: B");
else if(grade>=60)
printf("\n\t\tYour Grade is: C");
else if(grade>=50)
printf("\n\t\tYour Grade is: D");
else if(grade>=40)
printf("\n\t\tYour Grade is: E");
else/*end of If Condition*/
printf("\n\t\tYour grade is Below 39");
getch();
return 0;/*successful comletion of program statements*/
}
void getGrade(char ch)/*Function to Display the Prompts if user reply is true or false*/
{
int res;
res=rand()%4+1;
if(ch=='t')/*Checking if the user reply is true*/
{
switch(res)/*start of switch statement*/
{
case 1: printf("\n\nExcellent!!!");
break;
case 2: printf("\n\nVery Good!!!");
break;
case 3: printf("\n\nNice Work!!!");
break;
case 4: printf("\n\nKeep Up the Good Work!!");
break;

}/*end of switch case*/
}
else/*if the user reply is false*/
{
switch(res)/*start of switch case*/
{
case 1: printf("\n\nNo, Please Try Again!!");
break;
case 2: printf("\n\nWrong. Try Once More!!");
break;
case 3: printf("\n\nDon't Give Up!!");
break;
case 4: printf("\n\nNo. Keep Trying!!");
break;
}/*end of switch case*/
}/*end of if condition*/
}/*end of function*/


0

Response Number 3
Name: Wolfbone
Date: May 7, 2004 at 02:36:21 Pacific
Reply:

I don't have Windows so I'm afraid I can't run it. It looks like you'll need to replace the clrscr()s with system("clear")s, probably modify the random() calls and look at the Windows documentation for getche() and getch() so that you can replace them with equivalents from glibc. It can't be that difficult.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Installing 9.0 Restoring old partition a...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: Running c program in linux

How to run c program in linux www.computing.net/answers/linux/how-to-run-c-program-in-linux/28558.html

how to run c program in ubuntu www.computing.net/answers/linux/how-to-run-c-program-in-ubuntu/30296.html

running a program in new window www.computing.net/answers/linux/running-a-program-in-new-window-/29953.html