I am just learning c, and i was wondering how to stop my program from ending. The getchar () works fine with just the printf command, put what works with the scanf command?
Printable View
I am just learning c, and i was wondering how to stop my program from ending. The getchar () works fine with just the printf command, put what works with the scanf command?
If you really want a
Press any key to continue...
type thing, then you should check your compiler's keyboard or bios functions. If you need help with how to look up your compiler's documentation, just let us know what compiler you have.
Once you know the function, it's easy enough to implement..Code:printf ("Press any key to continue...\n");
for (;!kbhit(););
this should work and is the method i use
int wait = getch();
Well i tryed the getch(); but it doesnt work either and i use the software dev-c++.
Here is the code--
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
int main ()
{
printf("current age?\n");
scanf("%a");
printf("%a year olds are dumb\n");
getchar ();
return 0;
}
jobolikescake,
Try this code it should work for you.
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
//prototypes (your functions)
void pressKey();
int getAge();
//Global var
int a;
int main (){
a = getAge();
while(a < 1)
a = getAge();
if(a == 31){
printf("You are %d years old. Hey we are the same age!\n",a);
pressKey();
return 0;
}
if(a < 31)
printf("You are %d years old and you are still younger than me!\n",a);
else
printf("You are %d years old and you are now older than me!\n",a);
pressKey();
return 0;
}
int getAge(){
clrscr();
printf("\nWhat is your current age?\n");
scanf("%d",&a);
return(a);
}
void pressKey(){
printf("\nHit any key to continue...");
getch();
}:confused: :confused: :eek:
I cant even get that to run. It gives me a linker error saying permission denied.
What compiler are you using?
C or C++?
What OS?
I'm using Borlands C/C++ on WIN ME. And it works fine for me. what was the error message?
i use a c compiler on windows xp