I wish to know the necessity of inclusion of conio.h in c programming.what sort of a command is conio.h? what is its function in a c program? what if i don't include this command in my program? what type of files are stored in conio.h
What is conio.h in a c program?
First of all, conio.h is itself a file, called as 'header file'. The way you include it in your C program is called "preprocessor directive". This will just place all the function definitions in conio.h, in your program while compiling.
conio.h is used basically to clear screen (clrscr()), get characters (getch(), getche(), getchar()), print in colors (cprintf()) and text based graphics programming (like printing in colors, moving around the screen by specifying the position, etc).
Reply:"conio.h" means that 'consol input and output' and it contain ur consol input and ouput functions and perform the DOS base tasks
Reply:it is a header file used in old MS-DOS compilers.we should include this header file in our program when we use the functions like clrscr(),getch() and getche.
Reply:Its a header file.Console Input Output
flowers gifts
Monday, May 24, 2010
How to make a C/C++ program pause?
ok so I'm trying to learn C and C++, and whenever I execute the program it runs in the blink of an eye and I don't have time to see what it says, I remember there being a pause command or something that I could put in there somewhere that would wait for me to press enter, can you tell me where to put it and exactly what it's called? thank you
How to make a C/C++ program pause?
get in the habit of using getch() because it will work on all platforms (windows, unix, linux).
system("pause"); is Microsoft only.
Reply:Just add a getch(); before the last } of main. You will be fine.
Reply:There are a variety of ways -- basically you just need something that will cause the process to block.
One of these will work:
-Try reading in some input
-Use the sleep() command
-Use getch()
Reply:if the operating system is windows you can use
system("pause");
this function was declared in system.h I gues you should include the file. and for any operating system you can use scanf.
How to make a C/C++ program pause?
get in the habit of using getch() because it will work on all platforms (windows, unix, linux).
system("pause"); is Microsoft only.
Reply:Just add a getch(); before the last } of main. You will be fine.
Reply:There are a variety of ways -- basically you just need something that will cause the process to block.
One of these will work:
-Try reading in some input
-Use the sleep() command
-Use getch()
Reply:if the operating system is windows you can use
system("pause");
this function was declared in system.h I gues you should include the file. and for any operating system you can use scanf.
How do I compile C++ program in windows ?
is there any free or GNU g++ type compiler to compile C++ program in windows vista ?
How do I compile C++ program in windows ?
install cygwin, it has ports of g++ available that will compile under windows.
http://www.cygwin.com/
Reply:Microsoft Visual C++ Express may be useful:
http://www.microsoft.com/express/vc/
Reply:http://www.bloodshed.net/devcpp.html
You could try Dev-C++. It's what I use and I've never had any problems with it. It comes with MingW (A minimalist GCC port to Windows), so you don't have to deal with setting your own compiler up. There's also CodeBlocks, but I don't have any personal experience with that IDE.
daylily
How do I compile C++ program in windows ?
install cygwin, it has ports of g++ available that will compile under windows.
http://www.cygwin.com/
Reply:Microsoft Visual C++ Express may be useful:
http://www.microsoft.com/express/vc/
Reply:http://www.bloodshed.net/devcpp.html
You could try Dev-C++. It's what I use and I've never had any problems with it. It comes with MingW (A minimalist GCC port to Windows), so you don't have to deal with setting your own compiler up. There's also CodeBlocks, but I don't have any personal experience with that IDE.
daylily
Find 25^0.25 c program?
how can i solve (25^0.25) using c program
Find 25^0.25 c program?
#include %26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;math.h%26gt;
void main()
{
int a,b;
a=25;
clrscr();
b=pow(25,0.25);
printf("%d",%26amp;b);
}
getch();
Find 25^0.25 c program?
#include %26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;math.h%26gt;
void main()
{
int a,b;
a=25;
clrscr();
b=pow(25,0.25);
printf("%d",%26amp;b);
}
getch();
I'm trying to do a simple C program and I need to figure out how to check if a user input is an integer?
I'm doing a simple program that calculates sales tax to a purchase and displays the tax amount and the total cost. I'm using C (NOT C++) and the user will input the sale price then I am to convert that into the total sale and what the tax would be. Now I need to check the input that the user gives the program to verify that it is either a floating point or an integer. I think i need a float if they can use decimals right? Any help would be beneficial. Thank You For Your Time And Patience!!!
I'm trying to do a simple C program and I need to figure out how to check if a user input is an integer?
You can get sscanf to do much of the work for you. See below for some code I wrote to illustrate:
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;string.h%26gt;
#define MAX_STR_LEN 256
typedef enum { NONE = 0, INT, FLOAT, STRING, OTHER } DATA_TYPE;
typedef struct {
DATA_TYPE type;
union {
long i;
double f;
char s[MAX_STR_LEN];
} data;
} input_t;
int main(int argc, char *argv[])
{
char *s = argv[1];
input_t in = { NONE, { 0 } };
if (argc != 2) {
printf("\nusage: %s %26lt;n%26gt;\n",argv[0]);
exit(EXIT_FAILURE);
}
if ((strchr(s,'.') != NULL) %26amp;%26amp; (sscanf(s,"%lf",%26amp;in.data.f) == 1)) {
in.type = FLOAT;
} else if (sscanf(s,"%ld",%26amp;in.data.i) == 1) {
in.type = INT;
} else if (sscanf(s,"%s",in.data.s) == 1) {
in.type = STRING;
memcpy(in.data.s,s,sizeof(MAX_STR_LEN));
} else {
in.type = OTHER;
}
switch (in.type) {
case (INT):
printf("\nInt : %ld\n",in.data.i);
break;
case (FLOAT):
printf("\nFlt : %g\n",in.data.f);
break;
case (STRING):
printf("\nStr : %s\n",in.data.s);
break;
default:
puts("\nInvalid input");
break;
}
exit(EXIT_SUCCESS);
}
Reply:You can use float.
Float can handle int but Int cannot handle float or decimals.
Reply:well it is very simple just use float or decimal if use type only integer value then there is no such problem and you should display as it is.
I'm trying to do a simple C program and I need to figure out how to check if a user input is an integer?
You can get sscanf to do much of the work for you. See below for some code I wrote to illustrate:
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;string.h%26gt;
#define MAX_STR_LEN 256
typedef enum { NONE = 0, INT, FLOAT, STRING, OTHER } DATA_TYPE;
typedef struct {
DATA_TYPE type;
union {
long i;
double f;
char s[MAX_STR_LEN];
} data;
} input_t;
int main(int argc, char *argv[])
{
char *s = argv[1];
input_t in = { NONE, { 0 } };
if (argc != 2) {
printf("\nusage: %s %26lt;n%26gt;\n",argv[0]);
exit(EXIT_FAILURE);
}
if ((strchr(s,'.') != NULL) %26amp;%26amp; (sscanf(s,"%lf",%26amp;in.data.f) == 1)) {
in.type = FLOAT;
} else if (sscanf(s,"%ld",%26amp;in.data.i) == 1) {
in.type = INT;
} else if (sscanf(s,"%s",in.data.s) == 1) {
in.type = STRING;
memcpy(in.data.s,s,sizeof(MAX_STR_LEN));
} else {
in.type = OTHER;
}
switch (in.type) {
case (INT):
printf("\nInt : %ld\n",in.data.i);
break;
case (FLOAT):
printf("\nFlt : %g\n",in.data.f);
break;
case (STRING):
printf("\nStr : %s\n",in.data.s);
break;
default:
puts("\nInvalid input");
break;
}
exit(EXIT_SUCCESS);
}
Reply:You can use float.
Float can handle int but Int cannot handle float or decimals.
Reply:well it is very simple just use float or decimal if use type only integer value then there is no such problem and you should display as it is.
How to write a program in C by turning a hexadecimal to a decimal?
im having a hard time with this right now. help
write a c program that utilizes strings and numeric conversions
1. Read strings using a function you write called getStr ().
2. Write a function named hextodecimal () that takes in (only) a string parameter representing a positive hexadecimal number and return its decimal equivalent (integer). This function returns -1 if the string provided connotes to a negative number and/or is comprised of invalid characters.
-note: you may not use any library functions in this function- you must write all code necessary to enact the coversion and return the appropriate result.
-this function must accept both upper and lower case versions of the hex character.
-You may want to write an additional function that vets any string for invalid hex character
3. If original string is invalid, output an unambiguous message to the user and prompt for another input.
4. Output the original String, followed by its decimal equivalent. Clearly label which is which
How to write a program in C by turning a hexadecimal to a decimal?
I don't want to give you the entire solution, but I will give you some pieces to help, and comments where you need to fill in the code. This assignment justifiably restricts you from using library functions, which you would normally use to do much of the work for you. Use of fgets to get the user input is, I assume, allowed.
Note that I put the validity check in getStr, but part 2 of the problem statement wants you to check validity in hextodecimal, which is probably a better place to put it.
#include %26lt;stdio.h%26gt;
#include %26lt;string.h%26gt;
typedef enum { false = 0, true } Bool;
double Pow(const double x, const unsigned y);
int AtoI(const char c);
Bool isValidHexChar(const char c);
Bool getStr(char *s);
int hexToDec(char *s);
#define MAX_STR 256
int main(int argc, char *argv[]) {
char s[MAX_STR];
memset(s,0,sizeof(s));
if (getStr(s) == false) {
puts("\ninvalid entry");
} else {
printf("\n%s = %d\n",s,hexToDec(s));
}
return 0;
}
Bool getStr(char *s) {
char *p = s;
Bool isValidFlg = true;
/* prompt for hex value and read it using fgets */
/* remove '\n' from end of entered string */
/* loop for each character in the string, */
/* calling isValidHexChar( ) to check validity */
return isValidFlg;
}
int hexToDec(char *s) {
/* loop from the last char in s to the first, */
/* calling AtoI and Pow as you go to convert */
/* from hex to decimal */
return result;
}
double Pow(const double x, const unsigned y) {
double result = 1;
int i;
if (y %26gt; 0) {
for (i = 0; i %26lt; y; i++) {
result *= x;
}
}
return result;
}
int AtoI(const char c) {
int i = -1;
if (isValidHexChar(c) == true) {
if ((c %26gt;= '0') %26amp;%26amp; (c %26lt;= '9')) i = (int)c - 0x30;
else if ((c %26gt;= 'a') %26amp;%26amp; (c %26lt;= 'f')) i = (int)c - 0x57;
else i = (int)c - 0x37;
}
return i;
}
Bool isValidHexChar(const char c) {
Bool validFlg = false;
if (((c %26gt;= '0') %26amp;%26amp; (c %26lt;= '9')) ||
((c %26gt;= 'a') %26amp;%26amp; (c %26lt;= 'f')) ||
((c %26gt;= 'A') %26amp;%26amp; (c %26lt;= 'F'))) {
validFlg = true;
}
return validFlg;
}
Reply:try to avoid hexadecimal value....
write a c program that utilizes strings and numeric conversions
1. Read strings using a function you write called getStr ().
2. Write a function named hextodecimal () that takes in (only) a string parameter representing a positive hexadecimal number and return its decimal equivalent (integer). This function returns -1 if the string provided connotes to a negative number and/or is comprised of invalid characters.
-note: you may not use any library functions in this function- you must write all code necessary to enact the coversion and return the appropriate result.
-this function must accept both upper and lower case versions of the hex character.
-You may want to write an additional function that vets any string for invalid hex character
3. If original string is invalid, output an unambiguous message to the user and prompt for another input.
4. Output the original String, followed by its decimal equivalent. Clearly label which is which
How to write a program in C by turning a hexadecimal to a decimal?
I don't want to give you the entire solution, but I will give you some pieces to help, and comments where you need to fill in the code. This assignment justifiably restricts you from using library functions, which you would normally use to do much of the work for you. Use of fgets to get the user input is, I assume, allowed.
Note that I put the validity check in getStr, but part 2 of the problem statement wants you to check validity in hextodecimal, which is probably a better place to put it.
#include %26lt;stdio.h%26gt;
#include %26lt;string.h%26gt;
typedef enum { false = 0, true } Bool;
double Pow(const double x, const unsigned y);
int AtoI(const char c);
Bool isValidHexChar(const char c);
Bool getStr(char *s);
int hexToDec(char *s);
#define MAX_STR 256
int main(int argc, char *argv[]) {
char s[MAX_STR];
memset(s,0,sizeof(s));
if (getStr(s) == false) {
puts("\ninvalid entry");
} else {
printf("\n%s = %d\n",s,hexToDec(s));
}
return 0;
}
Bool getStr(char *s) {
char *p = s;
Bool isValidFlg = true;
/* prompt for hex value and read it using fgets */
/* remove '\n' from end of entered string */
/* loop for each character in the string, */
/* calling isValidHexChar( ) to check validity */
return isValidFlg;
}
int hexToDec(char *s) {
/* loop from the last char in s to the first, */
/* calling AtoI and Pow as you go to convert */
/* from hex to decimal */
return result;
}
double Pow(const double x, const unsigned y) {
double result = 1;
int i;
if (y %26gt; 0) {
for (i = 0; i %26lt; y; i++) {
result *= x;
}
}
return result;
}
int AtoI(const char c) {
int i = -1;
if (isValidHexChar(c) == true) {
if ((c %26gt;= '0') %26amp;%26amp; (c %26lt;= '9')) i = (int)c - 0x30;
else if ((c %26gt;= 'a') %26amp;%26amp; (c %26lt;= 'f')) i = (int)c - 0x57;
else i = (int)c - 0x37;
}
return i;
}
Bool isValidHexChar(const char c) {
Bool validFlg = false;
if (((c %26gt;= '0') %26amp;%26amp; (c %26lt;= '9')) ||
((c %26gt;= 'a') %26amp;%26amp; (c %26lt;= 'f')) ||
((c %26gt;= 'A') %26amp;%26amp; (c %26lt;= 'F'))) {
validFlg = true;
}
return validFlg;
}
Reply:try to avoid hexadecimal value....
WRITE A C -PROGRAM FOR FIBONACCI SERIES FOR n NUMBERS USING DO-WHILE STATEMENT.?
use c program
WRITE A C -PROGRAM FOR FIBONACCI SERIES FOR n NUMBERS USING DO-WHILE STATEMENT.?
well i suppose fibonacci no r
0 1 1 2 3 5 8 13
then ur code will be
int i =2;
int no[100];// say
no[0] = 0;
no[1] = 1;
do{
no[i] = no[i-2] + no[i-1];
i++;
printf( "%d th fib is::%d",i,no[i] );
}
while( i %26lt; 100);
Reply:Lol. I had to do this program in C and Java. Do your own homework man.
flamingo plant
WRITE A C -PROGRAM FOR FIBONACCI SERIES FOR n NUMBERS USING DO-WHILE STATEMENT.?
well i suppose fibonacci no r
0 1 1 2 3 5 8 13
then ur code will be
int i =2;
int no[100];// say
no[0] = 0;
no[1] = 1;
do{
no[i] = no[i-2] + no[i-1];
i++;
printf( "%d th fib is::%d",i,no[i] );
}
while( i %26lt; 100);
Reply:Lol. I had to do this program in C and Java. Do your own homework man.
flamingo plant
Subscribe to:
Posts (Atom)