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
Write a c program that will generate an arbitrary number of integers and store them in the file name numfile?
the c program one integer per line
Write a c program that will generate an arbitrary number of integers and store them in the file name numfile?
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
int
main(int argc, char* argv[])
{
int count = argc%26gt;1 ? atoi(argv[1]) : 10;
FILE *f = fopen("numfile", "w+");
if (!f)
perror("fopen"), exit(-1);
for (int i=0; i%26lt;count; i++)
fprintf(f, "%d\n", rand());
fclose(f);
return 0;
}
Write a c program that will generate an arbitrary number of integers and store them in the file name numfile?
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
int
main(int argc, char* argv[])
{
int count = argc%26gt;1 ? atoi(argv[1]) : 10;
FILE *f = fopen("numfile", "w+");
if (!f)
perror("fopen"), exit(-1);
for (int i=0; i%26lt;count; i++)
fprintf(f, "%d\n", rand());
fclose(f);
return 0;
}
Write a C++ Program that prints the block letter "B" IN A 7 x 6 grid of stars?
NOTE
using a C++ PROGRAM PLEASE!!
Write a C++ Program that prints the block letter "B" IN A 7 x 6 grid of stars?
Trisha,
As someone who teaches programming, I can tell you that this approach to homework is only going to hurt yourself (and probably cause you to fail the course).
All the concepts you're covering in class build upon one another... so if you don't learn to do this week's homework, you won't be able to do any of the following weeks' homework (not to mention tests and larger-scale projects).
Reply:I am really sorry to say. But try it on your own, if it is a project given to you. The hint is "Use for loop".
Reply:Do your own homework!
using a C++ PROGRAM PLEASE!!
Write a C++ Program that prints the block letter "B" IN A 7 x 6 grid of stars?
Trisha,
As someone who teaches programming, I can tell you that this approach to homework is only going to hurt yourself (and probably cause you to fail the course).
All the concepts you're covering in class build upon one another... so if you don't learn to do this week's homework, you won't be able to do any of the following weeks' homework (not to mention tests and larger-scale projects).
Reply:I am really sorry to say. But try it on your own, if it is a project given to you. The hint is "Use for loop".
Reply:Do your own homework!
I have a doubt in c++ program?
i have an error in c++ program.......its coming as an error 4 all the programs......the error is "fatal..\INCLUDE\CONIO%26gt;H 165: error directive: must use c++ for the type iostream". so wat correction am i supposed to make?
I have a doubt in c++ program?
I think you wrote a program as C++, but saved the file as a C file. For example, instead of naming the file MyProg.cpp, you called it MyProg.c. The compiler uses the file extension to determine if the program is a C program or a C++ program.
Reply:it is the error of your header files......either your library is corrupter or you need to set ur path by going in DOS shell.........
Reply:I wish you had provided your code because this looks like a relatively simple problem but wihtout your code it can be many types of things but one thing is for certain, thre previous responder (above this comment) is wrong in saying the file could be corrupt (that is just silly).....
Could you paste your code so i can take a look? Also it might be possible that your dev environment is set up to think its C specific or C++ (depending on which type you are trying to compile in)..
you should have either (or both):
#include %26lt;conio%26gt;
#include %26lt;iostream%26gt;
Notice you dont need to mention the ".h" extension for the conio portion if you are working with C++ code....And notice i didn't give the path to the library...the system knows where theya re already.
I have a doubt in c++ program?
I think you wrote a program as C++, but saved the file as a C file. For example, instead of naming the file MyProg.cpp, you called it MyProg.c. The compiler uses the file extension to determine if the program is a C program or a C++ program.
Reply:it is the error of your header files......either your library is corrupter or you need to set ur path by going in DOS shell.........
Reply:I wish you had provided your code because this looks like a relatively simple problem but wihtout your code it can be many types of things but one thing is for certain, thre previous responder (above this comment) is wrong in saying the file could be corrupt (that is just silly).....
Could you paste your code so i can take a look? Also it might be possible that your dev environment is set up to think its C specific or C++ (depending on which type you are trying to compile in)..
you should have either (or both):
#include %26lt;conio%26gt;
#include %26lt;iostream%26gt;
Notice you dont need to mention the ".h" extension for the conio portion if you are working with C++ code....And notice i didn't give the path to the library...the system knows where theya re already.
A program on a General tree having more than 2 child node in Data structure in C programming?
a C program on a General tree having more than 2 child node in Data structure in C programming. it is not a binary tree, but it should be a general tree where root node have three child node and each child node have three sub child node. want a help program on that
A program on a General tree having more than 2 child node in Data structure in C programming?
do you know how to implement double linked list ? please learn how to implement double linked list. this will solve your problem
umbrella plant
A program on a General tree having more than 2 child node in Data structure in C programming?
do you know how to implement double linked list ? please learn how to implement double linked list. this will solve your problem
umbrella plant
Write a C program that will convert Simple Sentences to Complex/Compound Sentence.?
Write a C program that will convert Simple Sentences to Complex/Compound Sentence.
Write a C program that will convert Simple Sentences to Complex/Compound Sentence.?
Cool. I think it is like taping into the state of the equation and filling the history
Write a C program that will convert Simple Sentences to Complex/Compound Sentence.?
Cool. I think it is like taping into the state of the equation and filling the history
Write a c program to merge sort 2 already sorted arrays?
how do i write a c program to merge sort 2 already sorted arrays?
Write a c program to merge sort 2 already sorted arrays?
Here is a small programme that will merge two sorted arrays of integer. You'll have to tweek it if you want to merge a different numeric type, and to add error checking -- I left all error checking out to make the code clearer.
#include %26lt;stdlib.h%26gt;
int *merge( int *a, int *b, int len )
{
int ai = 0; /* index into each array */
int bi = 0;
int *m = NULL;
int *mp = NULL;
mp = m = (int *) malloc( sizeof( int ) * len * 2); /* merged result*/
while( ai %26lt; len %26amp;%26amp; bi %26lt; len ) /* until one source is exhausted*/
{
if( *(a+ai) %26lt; *(b+bi) )
*mp++ = *(a+ai++);
else
*mp++ = *(b+bi++);
}
/* tack on the remainder of the array that was not exhausted */
while( ai %26lt; len )
*mp++ = *(a+ai++ );
while( bi %26lt; len )
*mp++ = *(b+bi++ );
return m; /* the merged array goes back to caller */
}
main( int argc, char **argv )
{
int first[] = { 1, 4, 8, 10, 12, 16, 22 };
int second[] = { 3, 6, 9, 12, 15, 18, 21 };
int *merged;
int i;
merged = merge( first, second, 7 );
for( i = 0; i %26lt; 14; i++ )
printf( "%d ", merged[i] );
printf( "\n" );
}
Write a c program to merge sort 2 already sorted arrays?
Here is a small programme that will merge two sorted arrays of integer. You'll have to tweek it if you want to merge a different numeric type, and to add error checking -- I left all error checking out to make the code clearer.
#include %26lt;stdlib.h%26gt;
int *merge( int *a, int *b, int len )
{
int ai = 0; /* index into each array */
int bi = 0;
int *m = NULL;
int *mp = NULL;
mp = m = (int *) malloc( sizeof( int ) * len * 2); /* merged result*/
while( ai %26lt; len %26amp;%26amp; bi %26lt; len ) /* until one source is exhausted*/
{
if( *(a+ai) %26lt; *(b+bi) )
*mp++ = *(a+ai++);
else
*mp++ = *(b+bi++);
}
/* tack on the remainder of the array that was not exhausted */
while( ai %26lt; len )
*mp++ = *(a+ai++ );
while( bi %26lt; len )
*mp++ = *(b+bi++ );
return m; /* the merged array goes back to caller */
}
main( int argc, char **argv )
{
int first[] = { 1, 4, 8, 10, 12, 16, 22 };
int second[] = { 3, 6, 9, 12, 15, 18, 21 };
int *merged;
int i;
merged = merge( first, second, 7 );
for( i = 0; i %26lt; 14; i++ )
printf( "%d ", merged[i] );
printf( "\n" );
}
Write a c program to simulate the movement of a caer?
The program should in C lanaguage and also related to Graphics designing.
Write a c program to simulate the movement of a caer?
I have this program on boat race. Take logic and have it as you desire.
#include%26lt;graphics.h%26gt;
#include%26lt;stdio.h%26gt;
#include%26lt;dos.h%26gt;
#include%26lt;math.h%26gt;
int b1,b2,b3,b4,b5,b6,j1=0,i1=0,i=DETECT,j,k...
FILE *fp;
char name[15];
void hai(int,int);
void main()
{
if(fopen("scores.txt","r")==NULL)
{
fp=fopen("scores.txt","w");
fprintf(fp,"0 0 0 0 0 0");
}
initgraph(%26amp;i,%26amp;j,"c:\\tc\\bgi");
setcolor(5);
settextstyle(1,0,6);
outtextxy(40,150,"welcome to boat race");
outtextxy(40,174,"----------------");
getch();
textmode(0);
textcolor(2);
cprintf("enter your name::");
cscanf("%s",%26amp;name);
printf("\n\n");
cprintf(" hai %s welcome to boat race",name);
printf("\n\n\n");
textcolor(14);
cprintf(" records of boats");
table();
printf("\n\n\n\n");
cprintf("see records and select a boat");
printf("\n\n");
cprintf("enter the boat no.::");
cscanf("%d",%26amp;n);
getch();
i=0;
initgraph(%26amp;i,%26amp;j,"c:\\tc\\bgi");
setcolor(14);
rectangle(1,1,getmaxx(),getmaxy());
rectangle(7,7,getmaxx()-7,getmaxy()-7)...
setfillstyle(1,2);
floodfill(6,6,14);
settextstyle(7,0,3);
outtextxy(23,23,"enter any key to start the game. . . . . . . . .");
while(j1!=1)
{i1++;
if(kbhit())
j1=1;}
getch();
j1=abs(i1);
setcolor(0);
settextstyle(7,0,3);
outtextxy(23,23,"enter any key to start the game. . . . . . . . .");
setcolor(15);
circle(500,55,30);
setfillstyle(1,14);
floodfill(500,55,15);
for(i=0;i%26lt;550;i++)
hai(i,j1);
getch();}
void hai(int i,int j1)
{int l;
for(j=0;j%26lt;251;j+=50)
{if(j==0)
{if((b1%26gt;180%26amp;%26amp;b1%26lt;240))
b1+=1;
else if(b1%26gt;250%26amp;%26amp;b1%26lt;400)
b1+=3;
else if((j1%8)%2==0)
b1+=(j1%8+1);
else
b1+=(j1%8);
i=b1;}
else if(j==50)
{if(b2%26gt;100%26amp;%26amp;b2%26lt;200)
b2+=5;
else if(b2%26gt;300%26amp;%26amp;b2%26lt;400)
b2+=5;
else if((j1%3)%2==0)
b2+=(j1%3+1);
else
b2+=j1%3;
i=b2;}
else if(j==100)
{if(b3%26gt;100%26amp;%26amp;b3%26lt;150)
b3+=3;
else if(b3%26gt;150%26amp;%26amp;b3%26lt;300)
b3+=5;
else if((j1%4)%2==0)
b3+=(j1%4+1);
else
b3+=j1%4;
i=b3;}
else if(j==150)
{if(b4%26gt;100%26amp;%26amp;b4%26lt;200)
b4+=3;
else if(b4%26gt;300%26amp;%26amp;b4%26lt;400)
b4+=3;
else if((j1%5)%2==0)
b4+=(j1%5+1);
else
b4+=j1%5;
i=b4;}
else if(j==200)
{if(b1%26gt;200%26amp;%26amp;b4%26lt;400)
b5+=3;
else if(b2%26gt;100%26amp;%26amp;b3%26lt;200)
b5+=3;
else if((j1%6)%2==0)
b5+=(j1%6+1);
else
b5+=j1%6;
i=b5;}
else if(j==250)
{if(b2%26gt;50%26amp;%26amp;b3%26lt;300)
b6+=1;
else if(b1%26gt;150%26amp;%26amp;b4%26lt;300)
b6+=3;
else if((j1%7)%2==0)
b6+=(j1%7+1);
else
b6+=j1%7;
i=b6;}
setcolor(2);
line(8,180+j,630,180+j);
setcolor(6);
ellipse(40+i,159+j,180,360,30,20);
setcolor(7);
circle(35+i,159+j,4);
arc(42+i,164+j,180,310,10);
if(i%2==0)
{line(35+i,167+j,48+i,174+j);
line(38+i,167+j,50+i,174+j);
setcolor(14);
line(50+i,170+j,40+i,200+j);}
else
{line(38+i,167+j,30+i,179+j);
line(35+i,167+j,28+i,180+j);
setcolor(14);
line(31+i,170+j,21+i,200+j);}
if(i%26gt;550%26amp;%26amp;i%26lt;560)
{l=10;
k=j;}}
if(l==10)
{setcolor(6);
fp=fopen("scores.txt","r+");
settextstyle(1,0,4);
switch(k/50+1)
{case 1:
outtextxy(30,230,"the winner of the game is 1st boat");
break;
case 2:
outtextxy(30,230,"the winner of the game is 2th boat");
break;
case 3:
outtextxy(30,230,"the winner of the game is 3th boat");
break;
case 4:
outtextxy(30,230,"the winner of the game is 4th boat");
break;
case 5:
outtextxy(30,230,"the winner of the game is 5th boat");
break;
case 6:
outtextxy(30,230,"the winner of the game is 6th boat");
}
if(n==(k/50+1))
outtextxy(30,270,"congrats ! you have won the match");
else
outtextxy(30,270,"sorry ! you have lost the match");
fseek(fp,(k/50)*12,0);
fscanf(fp,"%d",%26amp;c);
c+=1;
if(c%26gt;=10)
c=0;
fseek(fp,(k/50)*12,0);
fprintf(fp,"%d",c);
fclose(fp);
getch();
cleardevice();
exit(0);}
for(k=0;k%26lt;4;k++)
delay(2000000);
for(j=0;j%26lt;251;j+=50)
{if(j==0)
i=b1;
else if(j==50)
i=b2;
else if(j==100)
i=b3;
else if(j==150)
i=b4;
else if(j==200)
i=b5;
else if(j==250)
i=b6;
setcolor(0);
ellipse(40+i,159+j,180,360,30,20);
circle(35+i,159+j,4);
arc(42+i,164+j,180,310,10);
if(i%2==0)
{line(35+i,167+j,48+i,174+j);
line(38+i,167+j,50+i,174+j);
line(50+i,170+j,40+i,200+j);}
else
{line(38+i,167+j,30+i,179+j);
line(35+i,167+j,28+i,180+j);
line(31+i,170+j,21+i,200+j);}}}
table()
{
fp=fopen("scores.txt","r+");
for(j=0;j%26lt;7;j++)
for(i=10;i%26lt;15;i++)
{gotoxy(4+j*5,i);
cprintf("%c",'³');}
for(j=9;j%26lt;=15;j+=3)
for(i=4;i%26lt;35;i++)
{gotoxy(i,j);
cprintf("%c",'Ä');}
for(i=0;i%26lt;7;i+=3)
for(j=0;j%26lt;7;j++)
{gotoxy(4+j*5,9+i);
if(j==0)
cprintf("%c",'Ã');
else if(j==6)
cprintf("%c",'´');
else
cprintf("%c",'Å');}
for(i=0;i%26lt;6;i++)
{gotoxy(5+i*5,10);
printf("boat");
gotoxy(6+i*5,11);
printf("%d",i+1);
fseek(fp,i*12,0);
fscanf(fp,"%d",%26amp;c);
gotoxy(6+i*5,13);
printf("%d",c);}
getch();
}
visit us :: ebizwebbiz.com/mahesh_naidu/
ebizwebbiz.com/kchandureddy/
thank u
from
Indian
Write a c program to simulate the movement of a caer?
I have this program on boat race. Take logic and have it as you desire.
#include%26lt;graphics.h%26gt;
#include%26lt;stdio.h%26gt;
#include%26lt;dos.h%26gt;
#include%26lt;math.h%26gt;
int b1,b2,b3,b4,b5,b6,j1=0,i1=0,i=DETECT,j,k...
FILE *fp;
char name[15];
void hai(int,int);
void main()
{
if(fopen("scores.txt","r")==NULL)
{
fp=fopen("scores.txt","w");
fprintf(fp,"0 0 0 0 0 0");
}
initgraph(%26amp;i,%26amp;j,"c:\\tc\\bgi");
setcolor(5);
settextstyle(1,0,6);
outtextxy(40,150,"welcome to boat race");
outtextxy(40,174,"----------------");
getch();
textmode(0);
textcolor(2);
cprintf("enter your name::");
cscanf("%s",%26amp;name);
printf("\n\n");
cprintf(" hai %s welcome to boat race",name);
printf("\n\n\n");
textcolor(14);
cprintf(" records of boats");
table();
printf("\n\n\n\n");
cprintf("see records and select a boat");
printf("\n\n");
cprintf("enter the boat no.::");
cscanf("%d",%26amp;n);
getch();
i=0;
initgraph(%26amp;i,%26amp;j,"c:\\tc\\bgi");
setcolor(14);
rectangle(1,1,getmaxx(),getmaxy());
rectangle(7,7,getmaxx()-7,getmaxy()-7)...
setfillstyle(1,2);
floodfill(6,6,14);
settextstyle(7,0,3);
outtextxy(23,23,"enter any key to start the game. . . . . . . . .");
while(j1!=1)
{i1++;
if(kbhit())
j1=1;}
getch();
j1=abs(i1);
setcolor(0);
settextstyle(7,0,3);
outtextxy(23,23,"enter any key to start the game. . . . . . . . .");
setcolor(15);
circle(500,55,30);
setfillstyle(1,14);
floodfill(500,55,15);
for(i=0;i%26lt;550;i++)
hai(i,j1);
getch();}
void hai(int i,int j1)
{int l;
for(j=0;j%26lt;251;j+=50)
{if(j==0)
{if((b1%26gt;180%26amp;%26amp;b1%26lt;240))
b1+=1;
else if(b1%26gt;250%26amp;%26amp;b1%26lt;400)
b1+=3;
else if((j1%8)%2==0)
b1+=(j1%8+1);
else
b1+=(j1%8);
i=b1;}
else if(j==50)
{if(b2%26gt;100%26amp;%26amp;b2%26lt;200)
b2+=5;
else if(b2%26gt;300%26amp;%26amp;b2%26lt;400)
b2+=5;
else if((j1%3)%2==0)
b2+=(j1%3+1);
else
b2+=j1%3;
i=b2;}
else if(j==100)
{if(b3%26gt;100%26amp;%26amp;b3%26lt;150)
b3+=3;
else if(b3%26gt;150%26amp;%26amp;b3%26lt;300)
b3+=5;
else if((j1%4)%2==0)
b3+=(j1%4+1);
else
b3+=j1%4;
i=b3;}
else if(j==150)
{if(b4%26gt;100%26amp;%26amp;b4%26lt;200)
b4+=3;
else if(b4%26gt;300%26amp;%26amp;b4%26lt;400)
b4+=3;
else if((j1%5)%2==0)
b4+=(j1%5+1);
else
b4+=j1%5;
i=b4;}
else if(j==200)
{if(b1%26gt;200%26amp;%26amp;b4%26lt;400)
b5+=3;
else if(b2%26gt;100%26amp;%26amp;b3%26lt;200)
b5+=3;
else if((j1%6)%2==0)
b5+=(j1%6+1);
else
b5+=j1%6;
i=b5;}
else if(j==250)
{if(b2%26gt;50%26amp;%26amp;b3%26lt;300)
b6+=1;
else if(b1%26gt;150%26amp;%26amp;b4%26lt;300)
b6+=3;
else if((j1%7)%2==0)
b6+=(j1%7+1);
else
b6+=j1%7;
i=b6;}
setcolor(2);
line(8,180+j,630,180+j);
setcolor(6);
ellipse(40+i,159+j,180,360,30,20);
setcolor(7);
circle(35+i,159+j,4);
arc(42+i,164+j,180,310,10);
if(i%2==0)
{line(35+i,167+j,48+i,174+j);
line(38+i,167+j,50+i,174+j);
setcolor(14);
line(50+i,170+j,40+i,200+j);}
else
{line(38+i,167+j,30+i,179+j);
line(35+i,167+j,28+i,180+j);
setcolor(14);
line(31+i,170+j,21+i,200+j);}
if(i%26gt;550%26amp;%26amp;i%26lt;560)
{l=10;
k=j;}}
if(l==10)
{setcolor(6);
fp=fopen("scores.txt","r+");
settextstyle(1,0,4);
switch(k/50+1)
{case 1:
outtextxy(30,230,"the winner of the game is 1st boat");
break;
case 2:
outtextxy(30,230,"the winner of the game is 2th boat");
break;
case 3:
outtextxy(30,230,"the winner of the game is 3th boat");
break;
case 4:
outtextxy(30,230,"the winner of the game is 4th boat");
break;
case 5:
outtextxy(30,230,"the winner of the game is 5th boat");
break;
case 6:
outtextxy(30,230,"the winner of the game is 6th boat");
}
if(n==(k/50+1))
outtextxy(30,270,"congrats ! you have won the match");
else
outtextxy(30,270,"sorry ! you have lost the match");
fseek(fp,(k/50)*12,0);
fscanf(fp,"%d",%26amp;c);
c+=1;
if(c%26gt;=10)
c=0;
fseek(fp,(k/50)*12,0);
fprintf(fp,"%d",c);
fclose(fp);
getch();
cleardevice();
exit(0);}
for(k=0;k%26lt;4;k++)
delay(2000000);
for(j=0;j%26lt;251;j+=50)
{if(j==0)
i=b1;
else if(j==50)
i=b2;
else if(j==100)
i=b3;
else if(j==150)
i=b4;
else if(j==200)
i=b5;
else if(j==250)
i=b6;
setcolor(0);
ellipse(40+i,159+j,180,360,30,20);
circle(35+i,159+j,4);
arc(42+i,164+j,180,310,10);
if(i%2==0)
{line(35+i,167+j,48+i,174+j);
line(38+i,167+j,50+i,174+j);
line(50+i,170+j,40+i,200+j);}
else
{line(38+i,167+j,30+i,179+j);
line(35+i,167+j,28+i,180+j);
line(31+i,170+j,21+i,200+j);}}}
table()
{
fp=fopen("scores.txt","r+");
for(j=0;j%26lt;7;j++)
for(i=10;i%26lt;15;i++)
{gotoxy(4+j*5,i);
cprintf("%c",'³');}
for(j=9;j%26lt;=15;j+=3)
for(i=4;i%26lt;35;i++)
{gotoxy(i,j);
cprintf("%c",'Ä');}
for(i=0;i%26lt;7;i+=3)
for(j=0;j%26lt;7;j++)
{gotoxy(4+j*5,9+i);
if(j==0)
cprintf("%c",'Ã');
else if(j==6)
cprintf("%c",'´');
else
cprintf("%c",'Å');}
for(i=0;i%26lt;6;i++)
{gotoxy(5+i*5,10);
printf("boat");
gotoxy(6+i*5,11);
printf("%d",i+1);
fseek(fp,i*12,0);
fscanf(fp,"%d",%26amp;c);
gotoxy(6+i*5,13);
printf("%d",c);}
getch();
}
visit us :: ebizwebbiz.com/mahesh_naidu/
ebizwebbiz.com/kchandureddy/
thank u
from
Indian
Help with c program?
can u please tell me how to write a c program to generate adam numbers from 10 to 100.
an adam number is one which satisfies the following: the reverse of the square of a number is the square of the reverse of the number. that is if the number is 12 then 12^2=144,the reverse 441 which is 21^2
Help with c program?
#include%26lt;stdio.h%26gt;
void main()
{
int num, rev, sq, rev_sq;
int rev_int(int);//Function to get reverse of any number passed as parameter
for (num=10;num%26lt;100;num++)
{
sq = num*num; // square of all numbers from 10 to 100;
rev = rev_int(num); // gets reverse of num
rev_sq = rev_int(sq);// gets reverse of square
/* we check if the reverse of the square of the number is equal to the square of the reverse of the number.If found true then print the number else go to the next iteration*/
if(rev_sq == rev*rev)
printf("\n%d is Adams number",i);
}//end of for loop
}
int rev_number(int num)
{
int rev = 0;
while(num%10 !=0)
{
rev = rev + (num % 10) * 10;
num = num/10;
}
return rev;// returns the reverse
}//end of function
This program could be done with lot less variables.
Reply:I would loop through each number. In the loop:
1. convert number to string. Hold on to string and its reverse.
2. Square the number
3. convert the square to a string and reverse it.
4. Convert string to a number and get square root
5. Convert square root to string and compare to reverse of string in 1.
If they are equal, you have an adam number. Print it and move on to next number
If they are not, then move on to next number
Reply:Sounds to me like what you need to write, first, is a function which takes an int number, converts it to a string, reverses the string, then converts the reversed string into an integer for returning.
Then, you write a loop, from 10 to 100, in which the current index is passed to your function. That gives you the two values that have to prove to be an adam. Then you square both of those numbers. Then you need to compare the two squares to see if one is the reverse of the other. For that, you COULD use your function again on one of the two squares, then compare what is returned with what was generated.
Which class is this for - number theory? discrete math? Just curious. This kind of thing is so fun..
Too bad it has to be in C - in Perl or Tcl the code would be a lot simpler...
deliver flowers
an adam number is one which satisfies the following: the reverse of the square of a number is the square of the reverse of the number. that is if the number is 12 then 12^2=144,the reverse 441 which is 21^2
Help with c program?
#include%26lt;stdio.h%26gt;
void main()
{
int num, rev, sq, rev_sq;
int rev_int(int);//Function to get reverse of any number passed as parameter
for (num=10;num%26lt;100;num++)
{
sq = num*num; // square of all numbers from 10 to 100;
rev = rev_int(num); // gets reverse of num
rev_sq = rev_int(sq);// gets reverse of square
/* we check if the reverse of the square of the number is equal to the square of the reverse of the number.If found true then print the number else go to the next iteration*/
if(rev_sq == rev*rev)
printf("\n%d is Adams number",i);
}//end of for loop
}
int rev_number(int num)
{
int rev = 0;
while(num%10 !=0)
{
rev = rev + (num % 10) * 10;
num = num/10;
}
return rev;// returns the reverse
}//end of function
This program could be done with lot less variables.
Reply:I would loop through each number. In the loop:
1. convert number to string. Hold on to string and its reverse.
2. Square the number
3. convert the square to a string and reverse it.
4. Convert string to a number and get square root
5. Convert square root to string and compare to reverse of string in 1.
If they are equal, you have an adam number. Print it and move on to next number
If they are not, then move on to next number
Reply:Sounds to me like what you need to write, first, is a function which takes an int number, converts it to a string, reverses the string, then converts the reversed string into an integer for returning.
Then, you write a loop, from 10 to 100, in which the current index is passed to your function. That gives you the two values that have to prove to be an adam. Then you square both of those numbers. Then you need to compare the two squares to see if one is the reverse of the other. For that, you COULD use your function again on one of the two squares, then compare what is returned with what was generated.
Which class is this for - number theory? discrete math? Just curious. This kind of thing is so fun..
Too bad it has to be in C - in Perl or Tcl the code would be a lot simpler...
deliver flowers
Help in c++ program?
i want to write a program that calculates arithmatic and geometric mean in c++ , so i need help
Help in c++ program?
You aren't very specific with your request. How will the numbers be input (e.g. entered at the console, constant array, from a file) into the program? Any particular number format (e.g. integers, scientfic notation, simple floating point, double precision, fractions, sequence range, symbolic)?
Do you have a start to your program that you could share? This would help answer some the questions above. Is this a homework problem? Do you simply need hints regarding the general concepts for a computing solution or specific help on how to code certain aspects?
The arithmetic mean is pretty straight forward; it's just the average of your input numbers. However, the geometric mean can be done in several ways. I recommend taking the log of each input number, adding each log (i.e. multiply), dividing (i.e. nth-root) by the number of items, and finally the anti-log. Below is a quick attempt:
#include %26lt;math.h%26gt;
#include %26lt;iostream%26gt;
using namespace std;
int main () {
double nums[] ={8.3, 7.5, 1.9, 6.2, 2.4}; // input numbers
int numCount = sizeof(nums); // number of elements
double arithmetic_mean=0.0, geometric_mean=0.0;
for (int counter=0; counter%26lt;numCount; counter++) {
arithmetic_mean += nums[counter];
geometric_mean += log(nums[counter]);
}
arithmetic_mean /= numCount; // calc average
geometric_mean = exp(geometric_mean/numCount); // calc e ^ nth-root
cout %26lt;%26lt; "arithmetic mean = " %26lt;%26lt; arithmetic_mean %26lt;%26lt; endl;
cout %26lt;%26lt; "geometric mean = " %26lt;%26lt; geometric_mean %26lt;%26lt; endl;
return 0;
}
Obviously, you'll want to substitute the appropriate input code for the nums[] array. Also, I assumed double precision calculations but you may have different requirements.
Help in c++ program?
You aren't very specific with your request. How will the numbers be input (e.g. entered at the console, constant array, from a file) into the program? Any particular number format (e.g. integers, scientfic notation, simple floating point, double precision, fractions, sequence range, symbolic)?
Do you have a start to your program that you could share? This would help answer some the questions above. Is this a homework problem? Do you simply need hints regarding the general concepts for a computing solution or specific help on how to code certain aspects?
The arithmetic mean is pretty straight forward; it's just the average of your input numbers. However, the geometric mean can be done in several ways. I recommend taking the log of each input number, adding each log (i.e. multiply), dividing (i.e. nth-root) by the number of items, and finally the anti-log. Below is a quick attempt:
#include %26lt;math.h%26gt;
#include %26lt;iostream%26gt;
using namespace std;
int main () {
double nums[] ={8.3, 7.5, 1.9, 6.2, 2.4}; // input numbers
int numCount = sizeof(nums); // number of elements
double arithmetic_mean=0.0, geometric_mean=0.0;
for (int counter=0; counter%26lt;numCount; counter++) {
arithmetic_mean += nums[counter];
geometric_mean += log(nums[counter]);
}
arithmetic_mean /= numCount; // calc average
geometric_mean = exp(geometric_mean/numCount); // calc e ^ nth-root
cout %26lt;%26lt; "arithmetic mean = " %26lt;%26lt; arithmetic_mean %26lt;%26lt; endl;
cout %26lt;%26lt; "geometric mean = " %26lt;%26lt; geometric_mean %26lt;%26lt; endl;
return 0;
}
Obviously, you'll want to substitute the appropriate input code for the nums[] array. Also, I assumed double precision calculations but you may have different requirements.
Write a C Program to arrange a set of N numbers in an increasing order?
Write a C Program to arrange a set of N numbers in an increasing order
Write a C Program to arrange a set of N numbers in an increasing order?
This is a standard sort program. You can use bubble sort which is the simplest and inefficient in case of a lot of numbers. You could use insertion sortor merge sort and quick sort. Quick sort is a good choice for large set of numbers. Any algorithms book will tell you how these sorts work. You should refer those and try and code. If you are a beginner then I suggest u learn bubble sort. Its easy to learn and understand.
Reply:The C API has a built in implementation for sorting using quick sort, which is very efficient. The man, page with details on how it works is at:
http://www.hmug.org/man/3/qsort.php
C also provides heap and merge sort built in implementations.
Write a C Program to arrange a set of N numbers in an increasing order?
This is a standard sort program. You can use bubble sort which is the simplest and inefficient in case of a lot of numbers. You could use insertion sortor merge sort and quick sort. Quick sort is a good choice for large set of numbers. Any algorithms book will tell you how these sorts work. You should refer those and try and code. If you are a beginner then I suggest u learn bubble sort. Its easy to learn and understand.
Reply:The C API has a built in implementation for sorting using quick sort, which is very efficient. The man, page with details on how it works is at:
http://www.hmug.org/man/3/qsort.php
C also provides heap and merge sort built in implementations.
Write a C program that will convert Simple Sentences to Complex/Compound Sentence.?
Write a C program that will convert Simple Sentences to Complex/Compound Sentence.
Write a C program that will convert Simple Sentences to Complex/Compound Sentence.?
You already posted it here:
http://in.answers.yahoo.com/question/ind...
Reply:u have to include some other directory files in the library...
Reply:You sure you want to do this? if yes then here is the link and learn
http://64.233.183.104/search?q=cache:GlK...
Write a C program that will convert Simple Sentences to Complex/Compound Sentence.?
You already posted it here:
http://in.answers.yahoo.com/question/ind...
Reply:u have to include some other directory files in the library...
Reply:You sure you want to do this? if yes then here is the link and learn
http://64.233.183.104/search?q=cache:GlK...
Write a c program to evaluate a=(v-u)/t?
How do you end a c program starting with #include %26lt;stdio.h%26gt;?
Write a c program to evaluate a=(v-u)/t?
#include %26lt;stdio.h%26gt;
#include %26lt;conio.h%26gt;
int main()
{
int a,v,u,t;
clrscr();
printf("Enter v,u,t");
scanf("%d %d %d",%26amp;v,%26amp;u,%26amp;t);
a=(v-u)/t;
printf("a=%d",a);
getch();
return 0;
}
floral bouquets
Write a c program to evaluate a=(v-u)/t?
#include %26lt;stdio.h%26gt;
#include %26lt;conio.h%26gt;
int main()
{
int a,v,u,t;
clrscr();
printf("Enter v,u,t");
scanf("%d %d %d",%26amp;v,%26amp;u,%26amp;t);
a=(v-u)/t;
printf("a=%d",a);
getch();
return 0;
}
floral bouquets
Write a C program in a Unix Operating System to count number of word in a file.?
Write a C program in a Unix Operating System to count number of word in a file. The main process will read from the user the file name and a positive number N which represents the number of lines in this file. Accordingly, the main process will greate N processes. E#ach process i will count and print the numbe of words in i-th line of the input file, where 1%26lt;= i %26gt;=n. The children processes should be implemented using the system call exec. Finally, the main rocess should print out the total number of words in the input file.
Write a C program in a Unix Operating System to count number of word in a file.?
That sounds like a homework problem to me.. albeit an interesting one. While you are at it, remember that given a sufficiently large value of N, you could hose the box with too many execs.
I will abstain from trying to code it since I am a bit short of time. but briefly, I would approach this problem thus
- A method that takes a line and counts the number of words in it
- There should be a global counter for words in the file.
- the method mentioned above should enter a synchronous block to update this global counter
- The main program should invoke N such threads and to each thread, pass the ith line in the file.
- Each of the threads should invoke the method mentioned above.
- Once each thread returns, the main method should output the global count
My 2 cents!
Reply:linux man page for wc:
http://man.linuxquestions.org/index.php?...
Reply:The simpliest way for you is to take wc (words count) UNIX utility source and tailor it for your needs.
Write a C program in a Unix Operating System to count number of word in a file.?
That sounds like a homework problem to me.. albeit an interesting one. While you are at it, remember that given a sufficiently large value of N, you could hose the box with too many execs.
I will abstain from trying to code it since I am a bit short of time. but briefly, I would approach this problem thus
- A method that takes a line and counts the number of words in it
- There should be a global counter for words in the file.
- the method mentioned above should enter a synchronous block to update this global counter
- The main program should invoke N such threads and to each thread, pass the ith line in the file.
- Each of the threads should invoke the method mentioned above.
- Once each thread returns, the main method should output the global count
My 2 cents!
Reply:linux man page for wc:
http://man.linuxquestions.org/index.php?...
Reply:The simpliest way for you is to take wc (words count) UNIX utility source and tailor it for your needs.
Subscribe to:
Posts (Atom)