Okay so i am a girl 15 and im 5;6 and weight 120 wich disgusts me! so i was on a VEry struct diet wich i only ate fruits and my mom keeps forcing me to eat dinner! but she doesnt reaslize im just puking it up afterwords!! why wont she just let me follow my diet and i wont have to puke?! im really active i play soccer i swim adn im on the tennis team! so i shouldent need to puke up my food b.c im so athletic but she wont let me diet my own way! why would she do that?? thanks for your help !
LOVE!!
(( i do give best answer))
My mom is trying to kill me! help pleas?
OMG are you out of your mind?????? If you play sports then you know that you need to eat more. What is this obsession with teenage girl having to be so small that if you turn sideways you cant see them???????? I just don't get it I have been 5'8 scenes I was 14 and have never weighed less then 135 or it looked way to thin and unhealthy. you need to eat what your mom gives you and stop puking it up. This will cause all kinds of health problems if you don't!!! Please get some help if you cant stop Its just not healthy!!!!
Reply:my advice would be to confront you're mom and tell her that you are on a diet
if she doesn't trust your diet to be healthy, ask her to see a dietitian with you
that way your mom wont be able to deem your diet as "unhealthy"
Reply:Better listen to Mom because I think the fruit is interfering with your ability to spell.
Reply:(edited answer) I thought a little more about your question, so I decided to edit my anwser. I thought are you trying to follow a vegitaraian diet? If so as I stated in my previous anwser you still need to get protien. Depending on what type of vegitarian you want to be ,you can get protien from poultry, fish, eggs etc. But if you want nothing from animals you want to try to eat nuts, beans, and legumes You can get this from all types of food(original anwser)Your diet is not healthy and can cause problems. You need to have some kind of protien. Eatting just fruit is dangerous, and by being so active and not eatting enough calories, fat and protien can be dangerous. If you don't take in enough your body will start breaking down your muscles. Also by vommiting things up you can damage your teeth from the acid in your stomach, and can cause heart problems because throwing up disrupts the normal sodium, potassium and other electroltytes in your body. You are heading down a very dangerous road. You should consult your doctor about an approrpriate diet for you body type and activity level.
Reply:Ok, First of all. Being 120 is not alot..because im 5'6..and its not fat at all. And you should just eat a balanced diet LIke fruits and stuff like your doing..
but just tell your mom. that your on a diet..and she'll give you the portions you need. or just like wen she walks out of the room throw it in the trash.
Reply:I'm '5 "6 and 125 lbs.... I say just eat when your hungry and what you want.
Don't puke it up though. You might be bilemic and you should see a doctor about it.
Reply:You should eat more, you don't want to be anorexic. Just eat a balenced diet.
Reply:Your moms not trying to kill you. You need to eat more than just fruits. Eating only one kind of food is not healthy. YOU COULD DIE FROM DOING THAT. Don't puke up the other stuff that you eat. Your body needs the nutrients that the other food has that fruit does not.. While losing weight you can eat everything that you want....just in moderation
Reply:the only one trying to kill you is yourself, by puking up your food
Reply:your mom should let you eat what you wanna eat. its your decision. just say your not on a diet and you like fruits more...? lol i wish i could be more like you but i cant control my cravings
Reply:First of all the puking part is a bad habit to get into. I think that all your mom is trying to do is to give you a well balanced diet. Fruits by themselves are not enough.A well balanced diet, exercise, and an appropriate amount of sleep all together is the way to go. as for 120...ask a lot of other people to be honest about answering when you ask them how you look...Sometimes a person's bone structure allows them to carry more weight and still look great. LOL and your mom just cares about you.
Reply:Your weight is fine, you sound like you have an eating disorder....
Reply:Ask her for her to help you with your diet. Then she might feel like it's party her responsibility to keep you on it.
Reply:Grow up. You dont need to be on that strict of a diet at 15 years old. That is unhealthy in itself. You need nurishment that fruit alone is not giving you.
Reply:A fruit diet is a terrible idea. Why don't you just eat sugar instead. People with healthy diets who are trying to lose weight LIMIT the amount of fruit they eat a day. You should be eating more vegetables, not fruit.
Also, if you're athletic you NEED protein. You're pretty stupid for a 15 year old, don't they have health or nutrition classes in whatever podunk backwards town you live in?
Reply:No Comment.
Reply:Puking is not good...
Consult your mom about your diet, and she'll understand.
And if she still doesn't understand, try to eat a lot of greens during dinner.
I'm sure she would understand... *crosses fingers*
Reply:ok, you should try to stop the puking because it will destroy your teeth and throat lining. you shouldnt be on such a strict diet because of all ur athletics. i am a swimmer and i wouldnt be able to get thru 5 am practice if i didnt have dinner. you should talk to your mom and tell her what you want (like a goal weight and how you want to get there etc) and then you should listen to her concerns and try to come to a compromise between the two of you. good luck :]
Reply:My mom is the same way; she's always trying to get me to gain weight, even though I politely tell her no thank you. She probably just wants you to be healthy and eat normally. Moms can be protective like that. Sit her down and tell her that you are trying to stay healthy by following your diet (which may or may not be true, whatever works) and you would appreciate if she would support you in doing that. If she wants you yo sit down and eat with the family, put some food on your plate and move it around, so it looks like your eating. However, if you're playing sports, you should probably incorporate some protein into your diet, to make up for the muscle you are losing with your current diet (egg whites are great; they are only 20 calories per).
Reply:You can't just eat fruit, that is so unhealthy. People don't understand, that doesn't make you lose weight, it just puts it on because it stores all the fat you eat because your body knows it's not getting food.
She's not trying to kill you, she's saving you. My god.
If you are athletic you can't just eat fruit. You're going to end up passing out one of these days from lack of nutrition. You need to eat a variety of foods every day. That's why there's a pyramid of food that tells you what to eat everyday; because you NEED that food.
Tuesday, July 28, 2009
Please help me... pls correct these errors?
Please please i request u to correct the errors in this c++ program as fast as possible. please reply with the corrected program.. please..
//-----___-----___-----___-----____
// |
// HealthCare Pharmacy |
// Pricing and Monitoring System |
// |
//_____---_____---_____---_____---_|
#include %26lt;stdio.h%26gt;
#include %26lt;conio.h%26gt;
#include %26lt;ctype.h%26gt;
#include %26lt;string.h%26gt;
#include %26lt;dos.h%26gt;
#include "stdlib.h"
#define PIECES 50
#define DISCOUNT 0.03
#define MAXPWD 15
void details();
void add_item();
void search_item();
void search_by_brand();
void reports();
void main_header();
void pressany();
void date2day(int col, int row);
void next_page();
void log_in();
void menu();
char TypePassword[MAXPWD];
struct Drug
{
char ItemCode[10];
char BrandName[20];
char Description[20];
char Generic[20];
char Manufacturer[20];
char Indication[30];
char ItemLoc[30];
Please help me... pls correct these errors?
try this. what's it doing wrong? not making it past the compiler?
//-----___-----___-----___----...
// |
// HealthCare Pharmacy |
// Pricing and Monitoring System |
// |
//_____---_____---_____---____...
#include %26lt;stdio.h%26gt;
#include %26lt;conio.h%26gt;
#include %26lt;ctype.h%26gt;
#include %26lt;string.h%26gt;
#include %26lt;dos.h%26gt;
#include %26lt;stdlib.h%26gt;
#define PIECES 50
#define DISCOUNT 0.03
#define MAXPWD 15
void details();
void add_item();
void search_item();
void search_by_brand();
void reports();
void main_header();
void pressany();
void date2day(int col, int row);
void next_page();
void log_in();
void menu();
char TypePassword[MAXPWD];
struct Drug
{
char ItemCode[10];
char BrandName[20];
char Description[20];
char Generic[20];
char Manufacturer[20];
char Indication[30];
char ItemLoc[30];
}
Reply:struct Drug
{
char ItemCode[10];
char BrandName[20];
char Description[20];
char Generic[20];
char Manufacturer[20];
char Indication[30];
char ItemLoc[30];
}
or no main function ? haha. You have to make it clear man.
Reply:1) What are your errors?
2) Where's the rest of your code?
Reply:So, what errors are you getting?
//-----___-----___-----___-----____
// |
// HealthCare Pharmacy |
// Pricing and Monitoring System |
// |
//_____---_____---_____---_____---_|
#include %26lt;stdio.h%26gt;
#include %26lt;conio.h%26gt;
#include %26lt;ctype.h%26gt;
#include %26lt;string.h%26gt;
#include %26lt;dos.h%26gt;
#include "stdlib.h"
#define PIECES 50
#define DISCOUNT 0.03
#define MAXPWD 15
void details();
void add_item();
void search_item();
void search_by_brand();
void reports();
void main_header();
void pressany();
void date2day(int col, int row);
void next_page();
void log_in();
void menu();
char TypePassword[MAXPWD];
struct Drug
{
char ItemCode[10];
char BrandName[20];
char Description[20];
char Generic[20];
char Manufacturer[20];
char Indication[30];
char ItemLoc[30];
Please help me... pls correct these errors?
try this. what's it doing wrong? not making it past the compiler?
//-----___-----___-----___----...
// |
// HealthCare Pharmacy |
// Pricing and Monitoring System |
// |
//_____---_____---_____---____...
#include %26lt;stdio.h%26gt;
#include %26lt;conio.h%26gt;
#include %26lt;ctype.h%26gt;
#include %26lt;string.h%26gt;
#include %26lt;dos.h%26gt;
#include %26lt;stdlib.h%26gt;
#define PIECES 50
#define DISCOUNT 0.03
#define MAXPWD 15
void details();
void add_item();
void search_item();
void search_by_brand();
void reports();
void main_header();
void pressany();
void date2day(int col, int row);
void next_page();
void log_in();
void menu();
char TypePassword[MAXPWD];
struct Drug
{
char ItemCode[10];
char BrandName[20];
char Description[20];
char Generic[20];
char Manufacturer[20];
char Indication[30];
char ItemLoc[30];
}
Reply:struct Drug
{
char ItemCode[10];
char BrandName[20];
char Description[20];
char Generic[20];
char Manufacturer[20];
char Indication[30];
char ItemLoc[30];
}
or no main function ? haha. You have to make it clear man.
Reply:1) What are your errors?
2) Where's the rest of your code?
Reply:So, what errors are you getting?
Have another laugh... last part?
What does Sardarji do after taking photocopies? He compares it with the original for spelling mistakes.
--
What does Sardarji do when he has one white sheet and wants an extra sheet? He makes a photocopy of the white sheet.
--
Once Sardar was coming out of Airport. AS there was huge rush, the security, guard told Sardar, WAIT PLEASE! Sardar replied: 65Kgs and moved on.
--
Sardarji tried to light his cigarette. He struct the first match but it didnt lit. He tried another. It didn`t lit. The third one finally lit so he lit his cigarette carefully blow the match out and put it in his vest pocket. Friend asked why did u put that match in your vest pocket? Sardarji said: Thats a good match. I`ll use it again.
--
What do you do when a sardar throws a hand grenade at you?
Pull the pin and throw it back...
--
News: A 2-Seater Plane crashed in a graveyard in punjab, Local sardars have so far found 500 bodies and are still digging for more.
--
last one is my fav,
anyway, bye from me, c ya 2morow
Have another laugh... last part?
I don't care what you people say, those jokes were funny. It's not racist. You could just as easily replace Sardarji with a blonde person and make it a blonde joke.
Reply:LMAO lol i am arab to my name is reem so yup they were so funnny lmao : ) email me reem_xoxo@yahoo.com lol doze were funny
Reply:um... that wasn't funny. if anything that's racist/ religionist?
Making fun of some 'Sardarji' (whatever that is), you're probably just embittered because they attacked your country or something, and feel like attacking them by telling crude jokes.
either way, that isn't funny.
Reply:not funny.
Reply:I agree with angel..........these arent neccasarily racial...lol
surveys
--
What does Sardarji do when he has one white sheet and wants an extra sheet? He makes a photocopy of the white sheet.
--
Once Sardar was coming out of Airport. AS there was huge rush, the security, guard told Sardar, WAIT PLEASE! Sardar replied: 65Kgs and moved on.
--
Sardarji tried to light his cigarette. He struct the first match but it didnt lit. He tried another. It didn`t lit. The third one finally lit so he lit his cigarette carefully blow the match out and put it in his vest pocket. Friend asked why did u put that match in your vest pocket? Sardarji said: Thats a good match. I`ll use it again.
--
What do you do when a sardar throws a hand grenade at you?
Pull the pin and throw it back...
--
News: A 2-Seater Plane crashed in a graveyard in punjab, Local sardars have so far found 500 bodies and are still digging for more.
--
last one is my fav,
anyway, bye from me, c ya 2morow
Have another laugh... last part?
I don't care what you people say, those jokes were funny. It's not racist. You could just as easily replace Sardarji with a blonde person and make it a blonde joke.
Reply:LMAO lol i am arab to my name is reem so yup they were so funnny lmao : ) email me reem_xoxo@yahoo.com lol doze were funny
Reply:um... that wasn't funny. if anything that's racist/ religionist?
Making fun of some 'Sardarji' (whatever that is), you're probably just embittered because they attacked your country or something, and feel like attacking them by telling crude jokes.
either way, that isn't funny.
Reply:not funny.
Reply:I agree with angel..........these arent neccasarily racial...lol
surveys
Can you write this program?
Any one ? Please write a c program to process the students marks list. Algo is just scan number of marks from number of students and print them with particular columns and rows with average , rank, total.
Without using struct..... Only by using arrays and strings...
Can you write this program?
Yes, I can. Can YOU? Or should I ask, do you even want to bother?
Please don't post your homework assignments out here for other people to do for you. You need to do this work to learn. If you don't wish to learn, you should drop the course. If the work is too difficult, then talk to your instructor.
If there is something SPECIFIC that you need help with, then by all means, we will try to help you.
Reply:kid do you your homework by yourself.
Reply:Or else you may contact a C expert to code your project assignment. Check websites like http://askexpert.info/
Without using struct..... Only by using arrays and strings...
Can you write this program?
Yes, I can. Can YOU? Or should I ask, do you even want to bother?
Please don't post your homework assignments out here for other people to do for you. You need to do this work to learn. If you don't wish to learn, you should drop the course. If the work is too difficult, then talk to your instructor.
If there is something SPECIFIC that you need help with, then by all means, we will try to help you.
Reply:kid do you your homework by yourself.
Reply:Or else you may contact a C expert to code your project assignment. Check websites like http://askexpert.info/
Is there a detailed Time.h class explanation?
I'm relatively new to OOP, and was curious if someone could point me to a resource on the functions of the Time.h class in the C++/Dev-Cpp standard library, and how to use them. I want to write a program that reads the system time on (preferably) a remote computer on a LAN, but will be content if it would read the system time from the computer from which it is running. he program need to take a snapshot of the current time immediately after the user inputs a certain integer. I want to store these time to an array in a form (possibly a struct) so that I can manipulate it (add, subtract recall) it later. Any ideas?
Is there a detailed Time.h class explanation?
http://www.cplusplus.com/reference/clibr...
Google, as usual, is online 24/7 and is *very* useful.
Not sure what time.h has to do with OOP. Am I missing something here?
%26gt; I want to write a program that reads the system time on (preferably) a remote computer on a LAN
Not possible. Unless the remote computer broadcasts the system somehow, which doesn't really happen unless it happens to be a NTP server.
Look at the link I showed above. http://Cppreference.com also works.
Note. In C++, the header for time.h is ctime. #include %26lt;ctime%26gt;
Reply:This is as good as you will get it
http://en.wikipedia.org/wiki/Time.h
and since you want to use OOP, use a class instead of a structure.
Is there a detailed Time.h class explanation?
http://www.cplusplus.com/reference/clibr...
Google, as usual, is online 24/7 and is *very* useful.
Not sure what time.h has to do with OOP. Am I missing something here?
%26gt; I want to write a program that reads the system time on (preferably) a remote computer on a LAN
Not possible. Unless the remote computer broadcasts the system somehow, which doesn't really happen unless it happens to be a NTP server.
Look at the link I showed above. http://Cppreference.com also works.
Note. In C++, the header for time.h is ctime. #include %26lt;ctime%26gt;
Reply:This is as good as you will get it
http://en.wikipedia.org/wiki/Time.h
and since you want to use OOP, use a class instead of a structure.
Linker error: "undefined reference to..." I don't know how to fix :(?
I am using dev c++ and getting a linker error. I understand what it means somewhat, but I do not know how to fix it. Here is my program:
#include %26lt;stdio.h%26gt;
#include %26lt;winsock2.h%26gt;
int main(int argc, char *argv[])
{ int starts, s; sockaddr_in sockin; WSAData *wsa;
if(WSAStartup(MAKEWORD(1,1),wsa))
return 1;
starts=socket(AF_INET,SOCK_STREAM,IPPROT...
sockin.sin_family=AF_INET;
sockin.sin_addr.s_addr = INADDR_ANY;
sockin.sin_port=htons(40254);
if(!bind(starts,(sockaddr *)%26amp;sockin,sizeof(struct sockaddr_in)))
return 2;
scanf("");
WSACleanup();
return 0;
}
i get undefined reference to: 'WSAStartup@8', socket@12, htons@4, bind@12, WSACleanup@0
I do not really understand how to link a .dll. Thanks for your help.
Linker error: "undefined reference to..." I don't know how to fix :(?
Link to wsock32.lib (regular windows) or ws2_32.lib (windows NT) using the Input\Additional Dependencies field on the Linker tab/folder of the project Properties.
Reply:I'm glad I could be, at least, a little bit helpful. Happy programming! Report It
Reply:I'm not familar with the above code, though the error seems to imply you're missing a linking library.
In Dev++, create a new project, delete main.cpp file created. From that point, right click on project, select add to project (you would add your own cpp file).
Linking. Right click on project, select project options. At that point it's a matter of using the built add object or library button to locate your missing linker file. Once found, click ok.
#include %26lt;stdio.h%26gt;
#include %26lt;winsock2.h%26gt;
int main(int argc, char *argv[])
{ int starts, s; sockaddr_in sockin; WSAData *wsa;
if(WSAStartup(MAKEWORD(1,1),wsa))
return 1;
starts=socket(AF_INET,SOCK_STREAM,IPPROT...
sockin.sin_family=AF_INET;
sockin.sin_addr.s_addr = INADDR_ANY;
sockin.sin_port=htons(40254);
if(!bind(starts,(sockaddr *)%26amp;sockin,sizeof(struct sockaddr_in)))
return 2;
scanf("");
WSACleanup();
return 0;
}
i get undefined reference to: 'WSAStartup@8', socket@12, htons@4, bind@12, WSACleanup@0
I do not really understand how to link a .dll. Thanks for your help.
Linker error: "undefined reference to..." I don't know how to fix :(?
Link to wsock32.lib (regular windows) or ws2_32.lib (windows NT) using the Input\Additional Dependencies field on the Linker tab/folder of the project Properties.
Reply:I'm glad I could be, at least, a little bit helpful. Happy programming! Report It
Reply:I'm not familar with the above code, though the error seems to imply you're missing a linking library.
In Dev++, create a new project, delete main.cpp file created. From that point, right click on project, select add to project (you would add your own cpp file).
Linking. Right click on project, select project options. At that point it's a matter of using the built add object or library button to locate your missing linker file. Once found, click ok.
Drivers programming ( just read it if u know about system programming very good )?
hey guys if u want to answer me u must follow these steps
1) go and visit www.rootkit.com
2) download some source code such as 'FU_Rootkit"
3) delete all *.sys and *.exe
4) explore source code and if u r very good in drivers programming for windows u can find some API and struct and information that are not in standard document such as DDK
5) my question is "how the hell these guys find these information
6) and another example is this site "http://www.ntinternals.net"
u can find some information about windows nt (such as windows XP) that is not in standrad document
this is a good example "PEB" and "TEB"
PEB == process environment block and TEB == thread environment block , i searched my *.h and *.c and *.cpp in visual c++ 2005 but i cant find these information on it
finaly , please tell me how can i have these type information
Drivers programming ( just read it if u know about system programming very good )?
These guys as you call them do not find this information, they create it. If you want to understand it you need to learn programming to a very high standard. Don't expect others to tell you how it works, it would take years.
survey monkey
1) go and visit www.rootkit.com
2) download some source code such as 'FU_Rootkit"
3) delete all *.sys and *.exe
4) explore source code and if u r very good in drivers programming for windows u can find some API and struct and information that are not in standard document such as DDK
5) my question is "how the hell these guys find these information
6) and another example is this site "http://www.ntinternals.net"
u can find some information about windows nt (such as windows XP) that is not in standrad document
this is a good example "PEB" and "TEB"
PEB == process environment block and TEB == thread environment block , i searched my *.h and *.c and *.cpp in visual c++ 2005 but i cant find these information on it
finaly , please tell me how can i have these type information
Drivers programming ( just read it if u know about system programming very good )?
These guys as you call them do not find this information, they create it. If you want to understand it you need to learn programming to a very high standard. Don't expect others to tell you how it works, it would take years.
survey monkey
How to read a char type structure member properly? the code below is not working properly.?
#include%26lt;stdio.h%26gt;
struct account
{
int accno;
char acctype;
char name_accholder[10];
float balance;
}s1,*pt;
main()
{
pt=%26amp;s1;
puts("enter accno type name of acc_holder balance");
scanf("%d%c%s%f",%26amp;pt-%26gt;accno,%26amp;pt-%26gt;acctype...
%26amp;pt-%26gt;name_accholder,%26amp;pt-%26gt;balance);
printf(" accno %d acctype %c name %s balance %f", pt-%26gt;accno,pt-%26gt;acctype,pt-%26gt;name_accholder...
}
How to read a char type structure member properly? the code below is not working properly.?
Do one thing try removing the "%26amp;" symbol from the scanf statement. Check if that is making any difference. I am doubting on that only.
Reply:scanf("%d %c %s %f" ,%26amp;pt-%26gt;accno,%26amp;p...
this will solve your problem the spaces between the formatters will help scanf to recognise the input correctly else it takes the last key stroke(enter key) as an input for %c and crashes.
Reply:Be clear in ur ques. Is the char acctype is not printed properly or the name_accholder array?
Let me know the output which you got...
struct account
{
int accno;
char acctype;
char name_accholder[10];
float balance;
}s1,*pt;
main()
{
pt=%26amp;s1;
puts("enter accno type name of acc_holder balance");
scanf("%d%c%s%f",%26amp;pt-%26gt;accno,%26amp;pt-%26gt;acctype...
%26amp;pt-%26gt;name_accholder,%26amp;pt-%26gt;balance);
printf(" accno %d acctype %c name %s balance %f", pt-%26gt;accno,pt-%26gt;acctype,pt-%26gt;name_accholder...
}
How to read a char type structure member properly? the code below is not working properly.?
Do one thing try removing the "%26amp;" symbol from the scanf statement. Check if that is making any difference. I am doubting on that only.
Reply:scanf("%d %c %s %f" ,%26amp;pt-%26gt;accno,%26amp;p...
this will solve your problem the spaces between the formatters will help scanf to recognise the input correctly else it takes the last key stroke(enter key) as an input for %c and crashes.
Reply:Be clear in ur ques. Is the char acctype is not printed properly or the name_accholder array?
Let me know the output which you got...
The following statement as under plz tell me the answer?
a) the following statement
struct customer *ptr = malloc( sizeof( struct customer ) );
Given the sample allocation for the pointer "ptr" found above, How I can write a statement to reallocate ptr to be an array of 10 elements?
b) the following diagram that shows the possible connection between a pointer dp and the dynamic variable associated with it.
How we can Write c++ statements that generates code for this diagram any one can tell me.
The following statement as under plz tell me the answer?
Sorry, but I have no idea what in the world you might be babbling about.
Reply:Im sorry to waste more space like the guy above me, but I just wanted to say that the morons around these 'Q and A's' can't help you with any thing that doesnt involve 'going to the bathroom' or 'why my kid keeps crapping on the floor'. Instead you get guys like the one above me who just comes in here to waste peoples time and space to get some STTTTUUUUUPPPPIIIIIDDDDD points. Sorry I cant help, but I would suggest googling ''C++ forum'' or something along those lines
struct customer *ptr = malloc( sizeof( struct customer ) );
Given the sample allocation for the pointer "ptr" found above, How I can write a statement to reallocate ptr to be an array of 10 elements?
b) the following diagram that shows the possible connection between a pointer dp and the dynamic variable associated with it.
How we can Write c++ statements that generates code for this diagram any one can tell me.
The following statement as under plz tell me the answer?
Sorry, but I have no idea what in the world you might be babbling about.
Reply:Im sorry to waste more space like the guy above me, but I just wanted to say that the morons around these 'Q and A's' can't help you with any thing that doesnt involve 'going to the bathroom' or 'why my kid keeps crapping on the floor'. Instead you get guys like the one above me who just comes in here to waste peoples time and space to get some STTTTUUUUUPPPPIIIIIDDDDD points. Sorry I cant help, but I would suggest googling ''C++ forum'' or something along those lines
In the following statement ..............?
a) In the following statement
struct customer *ptr = malloc( sizeof( struct customer ) );
Given the sample allocation for the pointer "ptr" found above, write a statement to reallocate ptr to be an array of 10 elements?
b) Consider the following steps that shows the possible connection between a pointer dp and the dynamic variable associated with it.
1. Dp = 0045:02FE pointer Variable (Data segment)
2. *dp = 3.1415 dynamic variable (heap)
How I can Write c++ statements that generates code for these steps.
In the following statement ..............?
C++ Language Tutorial
http://www.cplusplus.com/doc/tutorial/
///
Reply:I didnt realize that this site was now used for HOMEWORK!! What a great idea?? Wish it was around when I was in school, maybe I would have gotten better grades, having someone answer my school projects!!!! You wont learn anything unless you actually do it yourself.
struct customer *ptr = malloc( sizeof( struct customer ) );
Given the sample allocation for the pointer "ptr" found above, write a statement to reallocate ptr to be an array of 10 elements?
b) Consider the following steps that shows the possible connection between a pointer dp and the dynamic variable associated with it.
1. Dp = 0045:02FE pointer Variable (Data segment)
2. *dp = 3.1415 dynamic variable (heap)
How I can Write c++ statements that generates code for these steps.
In the following statement ..............?
C++ Language Tutorial
http://www.cplusplus.com/doc/tutorial/
///
Reply:I didnt realize that this site was now used for HOMEWORK!! What a great idea?? Wish it was around when I was in school, maybe I would have gotten better grades, having someone answer my school projects!!!! You wont learn anything unless you actually do it yourself.
Pls help me?
i want file programe in c following Methods
pls sample programe
getc( fptr) à Reads a character from the file
putc (char, fptr) à Writes a character to the file
fputs (char[] , fptr) à Writes a line to the file
fgets (fptr, size, char[]) à Reads a line from the file
fprintf (fptr, “control string”, variable) à writes formatted input to the file
fscanf (fptr, “control string”, variables) à Reads formatted output to the screen
fread (struct variable, size of var, records , file ptr) à Reads a set of data like structure
fwrite(struct variable, size, record, fptr) à writes a set of data like structure
feof (fptr) à Checks whether we are at the end of the file or not
ftell (fp) à Tells the current cursor position
fseek (fp, (long) offset, position) à sets the cursor position
where offset à specifies the size of the cursor to be moved
position à 0 – from beginning
1 – from current place
Pls help me?
The input data for a program in real time always large and uses a large amount of data.The use of printf or scanf functions is not efficient programming as large input data reading becomes tedious .It is always advised to use files to store data on disks so it is never lost even if power is lost.There are quite good books like G.Balaguruswamy c.programming and let us c .......etc to start with .Use can easily know usage of commands with the sample program in those commands..............
online survey
pls sample programe
getc( fptr) à Reads a character from the file
putc (char, fptr) à Writes a character to the file
fputs (char[] , fptr) à Writes a line to the file
fgets (fptr, size, char[]) à Reads a line from the file
fprintf (fptr, “control string”, variable) à writes formatted input to the file
fscanf (fptr, “control string”, variables) à Reads formatted output to the screen
fread (struct variable, size of var, records , file ptr) à Reads a set of data like structure
fwrite(struct variable, size, record, fptr) à writes a set of data like structure
feof (fptr) à Checks whether we are at the end of the file or not
ftell (fp) à Tells the current cursor position
fseek (fp, (long) offset, position) à sets the cursor position
where offset à specifies the size of the cursor to be moved
position à 0 – from beginning
1 – from current place
Pls help me?
The input data for a program in real time always large and uses a large amount of data.The use of printf or scanf functions is not efficient programming as large input data reading becomes tedious .It is always advised to use files to store data on disks so it is never lost even if power is lost.There are quite good books like G.Balaguruswamy c.programming and let us c .......etc to start with .Use can easily know usage of commands with the sample program in those commands..............
online survey
Given the structure and pointer, what assignment statement sets the Price member of the structure pointed to?
by PC to 1000???????
struct Computer
{
char Manufacturer[30];
float Price;
int Memory;
} *PC;
int main (void)
{
struct Computer pc;
PC = %26amp;pc;
return 0;
}
a. PC-%26gt;Price=1000.0;
b. PC.Price=1000.0;
c. *PC.Price=1000.0;
d. Computer.Price=1000.0;
Given the structure and pointer, what assignment statement sets the Price member of the structure pointed to?
The answer is a).
PC is a pointer to a Computer.
To dereference a pointer, use -%26gt;.
Hence, the answer is PC-%26gt;Price = 1000.0;
You could also use (*PC).Price = 1000.0; however c) in the above example is wrong because it does not include brackets, which are required here.
struct Computer
{
char Manufacturer[30];
float Price;
int Memory;
} *PC;
int main (void)
{
struct Computer pc;
PC = %26amp;pc;
return 0;
}
a. PC-%26gt;Price=1000.0;
b. PC.Price=1000.0;
c. *PC.Price=1000.0;
d. Computer.Price=1000.0;
Given the structure and pointer, what assignment statement sets the Price member of the structure pointed to?
The answer is a).
PC is a pointer to a Computer.
To dereference a pointer, use -%26gt;.
Hence, the answer is PC-%26gt;Price = 1000.0;
You could also use (*PC).Price = 1000.0; however c) in the above example is wrong because it does not include brackets, which are required here.
Given the structure and pointer declarations below, which sets the Price member of the structure?
pointed to by PC to 1000
struct Computer
{
char Manufacturer [30};
floatPrice;
int Memory;
} *PC;
int main (void)
{
struct Computer pc;
PC = %26amp;pc;
return 0;
}
a. PC-%26gt;Price=1000.0;
b. PC.Price=1000.0;
c. *PC.Price=1000.0;
d. Computer.Price= 1000.0
Given the structure and pointer declarations below, which sets the Price member of the structure?
May you need to contact a C expert. Check http://k.aplis.net/
Reply:Well, I actually wrote out a legitiate answer to this question, assuming that it was an honest issue. However, after looking a bit longer at the questions page and seeing that every other question on the list was you asking another homework problem, I suddenly lost interest in helping you. Good luck with it, pointers can be a bit tricky.
struct Computer
{
char Manufacturer [30};
floatPrice;
int Memory;
} *PC;
int main (void)
{
struct Computer pc;
PC = %26amp;pc;
return 0;
}
a. PC-%26gt;Price=1000.0;
b. PC.Price=1000.0;
c. *PC.Price=1000.0;
d. Computer.Price= 1000.0
Given the structure and pointer declarations below, which sets the Price member of the structure?
May you need to contact a C expert. Check http://k.aplis.net/
Reply:Well, I actually wrote out a legitiate answer to this question, assuming that it was an honest issue. However, after looking a bit longer at the questions page and seeing that every other question on the list was you asking another homework problem, I suddenly lost interest in helping you. Good luck with it, pointers can be a bit tricky.
Can someone help me with client server error?
i am trying to complie this client.c using gcc -lsocket client.c
but i get these error:
warning: incompatible implicit declaration of built-in function 'bzero'
warning: incompatible implicit declaration of built-in function 'bcopy'
passing argument 2 of 'connect' from incompatible pointer type
warning: incompatible implicit declaration of built-in function 'strlen'
here is the code below:
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;sys/types.h%26gt;
#include %26lt;sys/socket.h%26gt;
#include %26lt;netinet/in.h%26gt;
#include %26lt;netdb.h%26gt;
void error(char *msg)
{
perror(msg);
exit(0);
}
int main(int argc, char *argv[])
{
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[256];
if (argc %26lt; 3) {
fprintf(stderr,"usage %s hostname port\n", argv[0]);
exit(0);
}
portno = atoi(argv[2]);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd %26lt; 0)
error("ERROR opening socket");
Can someone help me with client server error?
You have the same problem as this person:
http://www.thescripts.com/forum/thread21...
but i get these error:
warning: incompatible implicit declaration of built-in function 'bzero'
warning: incompatible implicit declaration of built-in function 'bcopy'
passing argument 2 of 'connect' from incompatible pointer type
warning: incompatible implicit declaration of built-in function 'strlen'
here is the code below:
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;sys/types.h%26gt;
#include %26lt;sys/socket.h%26gt;
#include %26lt;netinet/in.h%26gt;
#include %26lt;netdb.h%26gt;
void error(char *msg)
{
perror(msg);
exit(0);
}
int main(int argc, char *argv[])
{
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[256];
if (argc %26lt; 3) {
fprintf(stderr,"usage %s hostname port\n", argv[0]);
exit(0);
}
portno = atoi(argv[2]);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd %26lt; 0)
error("ERROR opening socket");
Can someone help me with client server error?
You have the same problem as this person:
http://www.thescripts.com/forum/thread21...
What is code of this data model?
( name [30]; age (int); address; status char[3];)
Address ( housenum; streetname; city_or_provname);
City_or_Provname ( type (this takes on a value of C if city add or P if provincial add); CityName [20]; ProvName [30]);
Outstanding_Student (name [30]; age (int); address; status char[3]);
Failed_Student (name [30]; age (int); address; status char[3]);
typedef struct
{
char name[30];
int age;
char status[3];
}STUDENT;
typedef struct
{
int housenum[30];
char streetname[30];
}ADDRESS;
typedef struct
{
char type[30];
union{
char CName[20];
char PROVINCE[30];
} union
}CITY_or_PROVINCE;
make a program using this data.
asking a user name, sex, address and status
in two given types of students.
and the output is what the user give.
What is code of this data model?
your declaration/definition of the data structures are not correct.
1. a data field of type ADDRESS (you have typedef-er the ADDRESS structure) should be a part of the struct STUDENT.
2. similarly a data field of type CITY_or_PROVINCE should be a part of the struct ADDRESS.
the above two are a requirement stated by your own problem definition.
also I don't see why you need 30 housenums in the ADDRESS struct and 30 type fields for the CITY_or_PROVINCE struct. (for both, 1, i.e. a single variable and not an array, should be enough).
after you have done a typedef of anything you can use it just like a "C" built-in type. so you can declare a student like this
STUDENT outstanding_stud, failed_stud;
use scanf for the user to input the individual fields..
ex.
scanf("%d", %26amp;outstanding_stud.address.housenum);
will result into the control waiting for the user to input an interger for the housenum and will store what the user enters in the housenum field of the address field of the outstanding_stud variable which is a structure of type STUDENT.
for output use printf like this:
printf("House Number: %d\n", outstanding_stud.address.housenum);
which will print:
House Number: 21
if the user has entered 21 for the house number.
you should figure out the rest.
bye!
salary survey
Address ( housenum; streetname; city_or_provname);
City_or_Provname ( type (this takes on a value of C if city add or P if provincial add); CityName [20]; ProvName [30]);
Outstanding_Student (name [30]; age (int); address; status char[3]);
Failed_Student (name [30]; age (int); address; status char[3]);
typedef struct
{
char name[30];
int age;
char status[3];
}STUDENT;
typedef struct
{
int housenum[30];
char streetname[30];
}ADDRESS;
typedef struct
{
char type[30];
union{
char CName[20];
char PROVINCE[30];
} union
}CITY_or_PROVINCE;
make a program using this data.
asking a user name, sex, address and status
in two given types of students.
and the output is what the user give.
What is code of this data model?
your declaration/definition of the data structures are not correct.
1. a data field of type ADDRESS (you have typedef-er the ADDRESS structure) should be a part of the struct STUDENT.
2. similarly a data field of type CITY_or_PROVINCE should be a part of the struct ADDRESS.
the above two are a requirement stated by your own problem definition.
also I don't see why you need 30 housenums in the ADDRESS struct and 30 type fields for the CITY_or_PROVINCE struct. (for both, 1, i.e. a single variable and not an array, should be enough).
after you have done a typedef of anything you can use it just like a "C" built-in type. so you can declare a student like this
STUDENT outstanding_stud, failed_stud;
use scanf for the user to input the individual fields..
ex.
scanf("%d", %26amp;outstanding_stud.address.housenum);
will result into the control waiting for the user to input an interger for the housenum and will store what the user enters in the housenum field of the address field of the outstanding_stud variable which is a structure of type STUDENT.
for output use printf like this:
printf("House Number: %d\n", outstanding_stud.address.housenum);
which will print:
House Number: 21
if the user has entered 21 for the house number.
you should figure out the rest.
bye!
salary survey
Definition of a class in object oriented programming?
I'm taking ANOTHER c++ course required for my degree in computer programming at my local community college, we are currently studying classes, I am not actually sure I understand the purpose of a class, since there ARE things like structs within the language.
Example, the definition of a struct is a collection of a fixed number of components in which the components are accessed by name, they MAY be of different types
Class- A collection of a fixed number of components. The components of a class are called members of the class.
This book even says that the ONLY difference between a struct and a class is the fact that by default all members of a struct are public, and all members of a class are private.
I do realize that within a class (not sure about struct) you are able to change the member access specifier...anyway...the question really is WHY are there classes if there are structs, am I just not getting the point yet?
Definition of a class in object oriented programming?
You need a class to be able to create new objects, a class encapsulates what the object is suppose to do / represent and should only expose methods for other users to access.
Anyone using your class does not have to worry about how it actually works internally, just how to use your methods that you designed within the class!
An explanation from the WIKI:
a class defines the abstract characteristics of a thing, including the thing's characteristics (its attributes or properties) and the things it can do (its behaviors or methods) or features). For example, the class 'Dogs' would consist of traits shared by all dogs, for example breed, fur color, and the ability to bark. Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. Also, the code for a class should be relatively self-contained. Collectively, the properties and methods defined by a class are called members.
Reply:http://www.aonaware.com/OOP1.htm
A tutorial.
Reply:Although the class and struct are effectively identical, the struct is there for backwards compatibility with C. There's also the issue of defaulting to public access vs private when comparing the two; which you mentioned.
Reply:struct is a simple data structure. But class is similar to functions.
Example, the definition of a struct is a collection of a fixed number of components in which the components are accessed by name, they MAY be of different types
Class- A collection of a fixed number of components. The components of a class are called members of the class.
This book even says that the ONLY difference between a struct and a class is the fact that by default all members of a struct are public, and all members of a class are private.
I do realize that within a class (not sure about struct) you are able to change the member access specifier...anyway...the question really is WHY are there classes if there are structs, am I just not getting the point yet?
Definition of a class in object oriented programming?
You need a class to be able to create new objects, a class encapsulates what the object is suppose to do / represent and should only expose methods for other users to access.
Anyone using your class does not have to worry about how it actually works internally, just how to use your methods that you designed within the class!
An explanation from the WIKI:
a class defines the abstract characteristics of a thing, including the thing's characteristics (its attributes or properties) and the things it can do (its behaviors or methods) or features). For example, the class 'Dogs' would consist of traits shared by all dogs, for example breed, fur color, and the ability to bark. Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. Also, the code for a class should be relatively self-contained. Collectively, the properties and methods defined by a class are called members.
Reply:http://www.aonaware.com/OOP1.htm
A tutorial.
Reply:Although the class and struct are effectively identical, the struct is there for backwards compatibility with C. There's also the issue of defaulting to public access vs private when comparing the two; which you mentioned.
Reply:struct is a simple data structure. But class is similar to functions.
Can you plz explain me with this?
content=//adding a new node at any place in a linked list
//acording to users choice
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;string.h%26gt;
#include%26lt;process.h%26gt;
struct abc
{
char n[20];
int p;
abc *next;
};
void main()
{
clrscr();
int c=0,per;
abc *list,*start=NULL,*ptr,*prev;
char nm[20],flag;
cout%26lt;%26lt;"enter the name and percentage marks of five children ";
for(int i=0;i%26lt;=4;i++)
{
if(start==NULL)
{
ptr=new abc;
cout%26lt;%26lt;"enter the details :";
cin%26gt;%26gt;ptr-%26gt;n%26gt;%26gt;ptr-%26gt;p;
start=ptr;
prev=ptr; //start=ptr=prev
}
else //implemented 4 times
{
ptr=new abc;
cin%26gt;%26gt;ptr-%26gt;n%26gt;%26gt;ptr-%26gt;p;
prev-%26gt;next=ptr;
prev=prev-%26gt;next;
}
}
int ch;
cout%26lt;%26lt;"\n enter the choice where the record is to be inserted \n";
cout%26lt;%26lt;"\n 1. starting of the list ";
cout%26lt;%26lt;"\n 2. in between ";
cout%26lt;%26lt;"\n 3. at the end";
cin%26gt;%26gt;ch;
list=new abc;
cout%26lt;%26lt;"\n enter the name and percent of new student :";
cin%26gt;%26gt;list-%26gt;n%26gt;%26gt;list-%26gt;p;
if (ch==1)
{
list-%26gt;next=start;
start=list;//now making list the starting point
}
else if(ch==3)
{
ptr=start;
while(ptr!=NULL)
{prev=ptr;
ptr=ptr-%26gt;next;
}
prev-%26gt;next=list;
list-%26gt;next=NULL;
}
else
{
cout%26lt;%26lt;"\n enter the record number (2-4) after which the node is to be inserted";
cin%26gt;%26gt;c;
if (c==1 || c==5)
{
cout%26lt;%26lt;"sorry wrong no. entered ";
exit(0);
}
i=0 ;
//insert the node
ptr=start;
cout%26lt;%26lt;"\n"%26lt;%26lt;"the list is :\n";
cout%26lt;%26lt;"name percentage\n";
while(ptr!=NULL)
{
i++;
if (i==c)
{
list-%26gt;next=ptr-%26gt;next; //????????
ptr-%26gt;next=list; //?????????????
}
ptr=ptr-%26gt;next;
}
}
ptr=start;
// display all the records ;
while (ptr!=NULL)
{
cout%26lt;%26lt;ptr-%26gt;n%26lt;%26lt;" "%26lt;%26lt;ptr-%26gt;p;
ptr=ptr-%26gt;next;
cout%26lt;%26lt;"\n";
}
getch();
}
Can you plz explain me with this?
list points to the new structure.
ptr points to the structure after which you will place list
so
list-%26gt;next = the next structure of where you are inserting list.
ptr-%26gt;next = list.
It basically places (list) in between ptr and ptr-%26gt;next.
Reply:Those two lines are simply moving some pointers. What exactly do you need explaining? Why do you need another example - surely the one you have is just fine?
I would recommend going and searching the net for C tutorials and references, and reading up on pointer operations. It might also be worth your time learning about linked lists and how they work.
survey
//acording to users choice
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;string.h%26gt;
#include%26lt;process.h%26gt;
struct abc
{
char n[20];
int p;
abc *next;
};
void main()
{
clrscr();
int c=0,per;
abc *list,*start=NULL,*ptr,*prev;
char nm[20],flag;
cout%26lt;%26lt;"enter the name and percentage marks of five children ";
for(int i=0;i%26lt;=4;i++)
{
if(start==NULL)
{
ptr=new abc;
cout%26lt;%26lt;"enter the details :";
cin%26gt;%26gt;ptr-%26gt;n%26gt;%26gt;ptr-%26gt;p;
start=ptr;
prev=ptr; //start=ptr=prev
}
else //implemented 4 times
{
ptr=new abc;
cin%26gt;%26gt;ptr-%26gt;n%26gt;%26gt;ptr-%26gt;p;
prev-%26gt;next=ptr;
prev=prev-%26gt;next;
}
}
int ch;
cout%26lt;%26lt;"\n enter the choice where the record is to be inserted \n";
cout%26lt;%26lt;"\n 1. starting of the list ";
cout%26lt;%26lt;"\n 2. in between ";
cout%26lt;%26lt;"\n 3. at the end";
cin%26gt;%26gt;ch;
list=new abc;
cout%26lt;%26lt;"\n enter the name and percent of new student :";
cin%26gt;%26gt;list-%26gt;n%26gt;%26gt;list-%26gt;p;
if (ch==1)
{
list-%26gt;next=start;
start=list;//now making list the starting point
}
else if(ch==3)
{
ptr=start;
while(ptr!=NULL)
{prev=ptr;
ptr=ptr-%26gt;next;
}
prev-%26gt;next=list;
list-%26gt;next=NULL;
}
else
{
cout%26lt;%26lt;"\n enter the record number (2-4) after which the node is to be inserted";
cin%26gt;%26gt;c;
if (c==1 || c==5)
{
cout%26lt;%26lt;"sorry wrong no. entered ";
exit(0);
}
i=0 ;
//insert the node
ptr=start;
cout%26lt;%26lt;"\n"%26lt;%26lt;"the list is :\n";
cout%26lt;%26lt;"name percentage\n";
while(ptr!=NULL)
{
i++;
if (i==c)
{
list-%26gt;next=ptr-%26gt;next; //????????
ptr-%26gt;next=list; //?????????????
}
ptr=ptr-%26gt;next;
}
}
ptr=start;
// display all the records ;
while (ptr!=NULL)
{
cout%26lt;%26lt;ptr-%26gt;n%26lt;%26lt;" "%26lt;%26lt;ptr-%26gt;p;
ptr=ptr-%26gt;next;
cout%26lt;%26lt;"\n";
}
getch();
}
Can you plz explain me with this?
list points to the new structure.
ptr points to the structure after which you will place list
so
list-%26gt;next = the next structure of where you are inserting list.
ptr-%26gt;next = list.
It basically places (list) in between ptr and ptr-%26gt;next.
Reply:Those two lines are simply moving some pointers. What exactly do you need explaining? Why do you need another example - surely the one you have is just fine?
I would recommend going and searching the net for C tutorials and references, and reading up on pointer operations. It might also be worth your time learning about linked lists and how they work.
survey
Plzz please help me??
well i try compiling my c++ project in visual c++ 6.0 ans get the following error.
-------------------Configuration: MainWnd - Win32 Debug--------------------
Linking...
MainWndDlg.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl SetHooks(struct HHOOK__ *,struct HHOOK__ *,struct HHOOK__ *,struct HWND__ *)" (__imp_?SetHooks@@YAXPAUHHOOK__@@00PAUHW...
MainWndDlg.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) long __stdcall MouseProc(int,unsigned int,long)" (__imp_?MouseProc@@YGJHIJ@Z)
MainWndDlg.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) long __stdcall KeyProc(int,unsigned int,long)" (__imp_?KeyProc@@YGJHIJ@Z)
Debug/MainWnd.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
MainWnd.exe - 4 error(s), 0 warning(s)
please someone help me i need to complete this project everything is depenent on this project.
Plzz please help me??
An unresolved external symbol means that you are trying to use classes / objects without properly linking to or including the right header files or declaring the proper namespaces.
It is also possible that you are executing the program with a different set of COM objects or DLLs than your version of Visual C++ supports.
Check your code to make sure you have called the correct header files and namespaces. Otherwise, you are probably better served installing Visual C++ 6 on a clean install of Windows 98 or the like, to ensure you are working with the proper libraries.
UPDATE:
Please do not communicate follow-ups to me privately via e-mail. Provide additional details here and then ask me to revisit the question.
I have explained this problem to you as succinctly as I can. You told me in your e-mail that you have copied some keylogger code from the Web and have tried to modify it.
The code you copied is clearly using libraries that either do not exist on your machine or you have failed to include in your code.
If you do not know what that means or you cannot figure out how to solve that yourself, then I cannot help you further.
-------------------Configuration: MainWnd - Win32 Debug--------------------
Linking...
MainWndDlg.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl SetHooks(struct HHOOK__ *,struct HHOOK__ *,struct HHOOK__ *,struct HWND__ *)" (__imp_?SetHooks@@YAXPAUHHOOK__@@00PAUHW...
MainWndDlg.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) long __stdcall MouseProc(int,unsigned int,long)" (__imp_?MouseProc@@YGJHIJ@Z)
MainWndDlg.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) long __stdcall KeyProc(int,unsigned int,long)" (__imp_?KeyProc@@YGJHIJ@Z)
Debug/MainWnd.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
MainWnd.exe - 4 error(s), 0 warning(s)
please someone help me i need to complete this project everything is depenent on this project.
Plzz please help me??
An unresolved external symbol means that you are trying to use classes / objects without properly linking to or including the right header files or declaring the proper namespaces.
It is also possible that you are executing the program with a different set of COM objects or DLLs than your version of Visual C++ supports.
Check your code to make sure you have called the correct header files and namespaces. Otherwise, you are probably better served installing Visual C++ 6 on a clean install of Windows 98 or the like, to ensure you are working with the proper libraries.
UPDATE:
Please do not communicate follow-ups to me privately via e-mail. Provide additional details here and then ask me to revisit the question.
I have explained this problem to you as succinctly as I can. You told me in your e-mail that you have copied some keylogger code from the Web and have tried to modify it.
The code you copied is clearly using libraries that either do not exist on your machine or you have failed to include in your code.
If you do not know what that means or you cannot figure out how to solve that yourself, then I cannot help you further.
I dont know y i m getting wrong answer?
Sample Input
Dear Sally,
Please, please do it--1 would 4
Mary very, 1 much. And 4 6
8 everything in 5's power to make
14 pay off for you.
-- Thank 2 18 18--
0
Sample Output
Dear Sally,
Please, please do it--it would please
Mary very, very much. And Mary would
do everything in Mary's power to make
it pay off for you.
/*Uncompress*/
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
typedef struct listnode *ptr;
typedef struct listnode{
char word[50];
ptr link;
};
ptr creat(char *word){
ptr node;
node=malloc(sizeof(struct listnode));
strcpy(node-%26gt;word,word);
node-%26gt;link=NULL;
return node;
}
ptr insert(ptr list,char *word){
ptr node;
node=creat(word);
node-%26gt;link=list;
return node;
}
inorder(ptr list,int n){
int i;
ptr phead,temp;
phead=list;
for(i=1;i%26lt;n;i++){
temp=list;
list=list-%26gt;link;
}
printf("%s",list-%26gt;word);
if(n%26gt;1){
temp-%26gt;link=list-%26gt;link;
list=insert(phead,list-%26gt;word);
}
return list;
}
int main()
{
int p=0,k=0,s=0,n=0;
char t,word[50];
ptr list;
list=creat(" ");
while(scanf("%c",%26amp;t)!=EOF %26amp;%26amp; t!='0'){
if(isalpha(t)){word[p++]=t; printf("%c",t); s=1;}
else if(t%26gt;=48 %26amp;%26amp; t%26lt;58){ k=1; n*=10; n+=t-48; }
else{
if(!k %26amp;%26amp; s){word[p]='\0'; list=insert(list,word); p=0; s=0; printf("%c",t);}
else if(k){list=inorder(list,n);k=0... n=0; printf("%c",t);}
else printf("%c",t);
}
}
return 0;
}
I dont know y i m getting wrong answer?
i think it would help if you said what it is you are trying to do in the first place, and what is failing.
Dear Sally,
Please, please do it--1 would 4
Mary very, 1 much. And 4 6
8 everything in 5's power to make
14 pay off for you.
-- Thank 2 18 18--
0
Sample Output
Dear Sally,
Please, please do it--it would please
Mary very, very much. And Mary would
do everything in Mary's power to make
it pay off for you.
/*Uncompress*/
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
typedef struct listnode *ptr;
typedef struct listnode{
char word[50];
ptr link;
};
ptr creat(char *word){
ptr node;
node=malloc(sizeof(struct listnode));
strcpy(node-%26gt;word,word);
node-%26gt;link=NULL;
return node;
}
ptr insert(ptr list,char *word){
ptr node;
node=creat(word);
node-%26gt;link=list;
return node;
}
inorder(ptr list,int n){
int i;
ptr phead,temp;
phead=list;
for(i=1;i%26lt;n;i++){
temp=list;
list=list-%26gt;link;
}
printf("%s",list-%26gt;word);
if(n%26gt;1){
temp-%26gt;link=list-%26gt;link;
list=insert(phead,list-%26gt;word);
}
return list;
}
int main()
{
int p=0,k=0,s=0,n=0;
char t,word[50];
ptr list;
list=creat(" ");
while(scanf("%c",%26amp;t)!=EOF %26amp;%26amp; t!='0'){
if(isalpha(t)){word[p++]=t; printf("%c",t); s=1;}
else if(t%26gt;=48 %26amp;%26amp; t%26lt;58){ k=1; n*=10; n+=t-48; }
else{
if(!k %26amp;%26amp; s){word[p]='\0'; list=insert(list,word); p=0; s=0; printf("%c",t);}
else if(k){list=inorder(list,n);k=0... n=0; printf("%c",t);}
else printf("%c",t);
}
}
return 0;
}
I dont know y i m getting wrong answer?
i think it would help if you said what it is you are trying to do in the first place, and what is failing.
Look at this program: Answer the ?'s -please?
#include%26lt;stdio.h%26gt;
struct vector
{
float x;
float y;
float z;
};
float scalar (vector*, vector *);
int main(void)
{
struct vector a ={2.3,4.2, 6.5};
struct vector b = {-1.2, 3.5, 5.1};
printf ("the answer is %.2f", scalar (%26amp;a, %26amp;b));
}
float scalar (struct vector*po1, struct vector *po2)
{
float s;
s= po1-%26gt;x*po2-%26gt;x + po1-%26gt;y*po2-%26gt;y+po1-%26gt;z*po2-%26gt;z;
return (s);
}
After running this program the screen will:
a. 45.0900000
b.45.09
c. the answer is 45.09
d. the answer is 45.090000
Also:
the scalar( ) function uses po1-%26gt;x to access the 1st member of the structure which other one can be equally used to access the same member?
a. po1.x
b. *po1.x
c.(*po1).x
d. a.x
Look at this program: Answer the ?'s -please?
both answers are c.
Reply:It won't compile for me. = ( it closes right away.
struct vector
{
float x;
float y;
float z;
};
float scalar (vector*, vector *);
int main(void)
{
struct vector a ={2.3,4.2, 6.5};
struct vector b = {-1.2, 3.5, 5.1};
printf ("the answer is %.2f", scalar (%26amp;a, %26amp;b));
}
float scalar (struct vector*po1, struct vector *po2)
{
float s;
s= po1-%26gt;x*po2-%26gt;x + po1-%26gt;y*po2-%26gt;y+po1-%26gt;z*po2-%26gt;z;
return (s);
}
After running this program the screen will:
a. 45.0900000
b.45.09
c. the answer is 45.09
d. the answer is 45.090000
Also:
the scalar( ) function uses po1-%26gt;x to access the 1st member of the structure which other one can be equally used to access the same member?
a. po1.x
b. *po1.x
c.(*po1).x
d. a.x
Look at this program: Answer the ?'s -please?
both answers are c.
Reply:It won't compile for me. = ( it closes right away.
How to use qsort function in stdlib.h ?
/*In the file stdlib.h, I find this procedure*/
_CRTIMP void __cdecl qsort(void *, size_t, size_t, int (__cdecl *)
(const void *, const void *));
/*which is why I think that this is actually a command to quick sort some kind of struct.
If there is a struct defined like below*/
struct DataBase
{ int Value;
char Name[20],Address[20];
float A,B,C;
} *VData;
void main(void)
{ int NumOfData;
NumOfData=TakeDataFromFile
(VData,"DataFile.txt");
????
WriteSortedData
(NumOfData,VData,"SortedData.txt");
}
/*Please write on the ???? how to sort the struct using the qsort procedure in the stdlib.h
Please also tell me if I have to make some kind of procedure outside the void main(void) */
How to use qsort function in stdlib.h ?
The qsort() is a generic function to sort any array. Let's assume that in the given structure you would like to sort on Name. Just incase two people have the same name you would like to sort on Value.
You need to write a custom compare function that would implement the above logic.
// Function to compare two DataBase elements.
int DataBaseCmp(const void *elem1, const void *elem2) {
// Typecast elements back to DataBase* type from void*
Database *dbelem1 = (const Database *)elem1;
Database *dbelem2 = (const Database *)elem2;
int diff;
// Compare names
diff = strcmp(dbelem1-%26gt;Name, dbelem2-%26gt;Name);
// If names are same, compare values
if( diff == 0 ) {
return dbelem1-%26gt;Value - dbelem2-%26gt;Value;
}
else {
return diff;
}
}
== qsort signature ==
void qsort(
void *base,
size_t num,
size_t width,
int (__cdecl *compare )(const void *, const void *)
);
=================
qsort(VData, NumOfData, sizeof(Database), DataBaseCmp);
Reply:http://www.cppreference.com/stdother/qso...
Generally,searching on Google proves to be very useful.
Reply:If we have DataBase itemA and itemB, under what condition itemA is less than itemB? Sort by value, by name or by address? You should define this first.
land survey
_CRTIMP void __cdecl qsort(void *, size_t, size_t, int (__cdecl *)
(const void *, const void *));
/*which is why I think that this is actually a command to quick sort some kind of struct.
If there is a struct defined like below*/
struct DataBase
{ int Value;
char Name[20],Address[20];
float A,B,C;
} *VData;
void main(void)
{ int NumOfData;
NumOfData=TakeDataFromFile
(VData,"DataFile.txt");
????
WriteSortedData
(NumOfData,VData,"SortedData.txt");
}
/*Please write on the ???? how to sort the struct using the qsort procedure in the stdlib.h
Please also tell me if I have to make some kind of procedure outside the void main(void) */
How to use qsort function in stdlib.h ?
The qsort() is a generic function to sort any array. Let's assume that in the given structure you would like to sort on Name. Just incase two people have the same name you would like to sort on Value.
You need to write a custom compare function that would implement the above logic.
// Function to compare two DataBase elements.
int DataBaseCmp(const void *elem1, const void *elem2) {
// Typecast elements back to DataBase* type from void*
Database *dbelem1 = (const Database *)elem1;
Database *dbelem2 = (const Database *)elem2;
int diff;
// Compare names
diff = strcmp(dbelem1-%26gt;Name, dbelem2-%26gt;Name);
// If names are same, compare values
if( diff == 0 ) {
return dbelem1-%26gt;Value - dbelem2-%26gt;Value;
}
else {
return diff;
}
}
== qsort signature ==
void qsort(
void *base,
size_t num,
size_t width,
int (__cdecl *compare )(const void *, const void *)
);
=================
qsort(VData, NumOfData, sizeof(Database), DataBaseCmp);
Reply:http://www.cppreference.com/stdother/qso...
Generally,searching on Google proves to be very useful.
Reply:If we have DataBase itemA and itemB, under what condition itemA is less than itemB? Sort by value, by name or by address? You should define this first.
land survey
Can someone convert the code to java...... !!!?
////////////////////////////////////////...
// ShapeFileReader.cpp: implementation of the ShapeFileReader class.
//////////////////////////////////////...
#include "iostream.h"
#include "fstream.h"
#include "ShapeFileReader.h"
#include "MainHeader.h"
#include "RecordHeader.h"
#include "Point.h"
#include "Polygon.h"
#include "MultiPoint.h"
#include "PolyLine.h"
const char* FILENAME = "c:/shapes/cities.shp";
int getTotalShapes();
MainHeader mh;
Point *pt;
MultiPoint *mp;
Polygon *pg;
PolyLine *pl;
void main()
{
RecordHeader rh;
ifstream inp;
int index=0;
int l_totalShapes = getTotalShapes();
inp.open(FILENAME,ios::in, filebuf::openprot);
inp.setmode(filebuf::binary);
inp.read((char*)%26amp;mh, 100);
cout %26lt;%26lt; "\n File Code = " %26lt;%26lt; mh.getFileCode();
cout %26lt;%26lt; "\n File Length = " %26lt;%26lt; mh.getFileLength();
cout %26lt;%26lt; "\n Version = " %26lt;%26lt; mh.getVersion();
cout %26lt;%26lt; "\n Shape Type = " %26lt;%26lt; mh.getShapeType();
cout %26lt;%26lt; "\n xMin = " %26lt;%26lt; mh.getXMin();
cout %26lt;%26lt; "\n yMin = " %26lt;%26lt; mh.getYMin();
cout %26lt;%26lt; "\n xMax = " %26lt;%26lt; mh.getXMax();
cout %26lt;%26lt; "\n yMax = " %26lt;%26lt; mh.getYMax();
cout %26lt;%26lt; "\n zMin = " %26lt;%26lt; mh.getZMin();
cout %26lt;%26lt; "\n zMax = " %26lt;%26lt; mh.getZMax();
cout %26lt;%26lt; "\n mMin = " %26lt;%26lt; mh.getMMin();
cout %26lt;%26lt; "\n mMax = " %26lt;%26lt; mh.getMMax();
cout %26lt;%26lt; "\n Total shapes = " %26lt;%26lt; l_totalShapes;
switch (mh.getShapeType())
{
case POINT:
pt = new Point[l_totalShapes];
break;
case POLYLINE:
pl = new PolyLine[l_totalShapes];
break;
case POLYGON:
pg = new Polygon[l_totalShapes];
break;
case MULTIPOINT:
mp = new MultiPoint[l_totalShapes];
break;
}
while (index %26lt; l_totalShapes)
{
inp.read((char*)%26amp;rh,8);
if(inp.eof())
break;
switch(mh.getShapeType())
{
case POINT:
inp.read((char*)(pt+index),20);
break;
case POLYLINE:
{
int *l_ptrParts = NULL;
struct point *l_ptrPoints = NULL;
inp.read((char*)(pl+index),44);
l_ptrParts = new int[pl[index].getNumParts()];
l_ptrPoints = new struct point[pl[index].getNumPoints()];
pl[index].setParts(l_ptrParts);
pl[index].setPoints(l_ptrPoints);
inp.read((char*)l_ptrParts, (sizeof(int)*pl[index].getNumParts()));
inp.read((char*)l_ptrPoints, (sizeof(struct point)*pl[index].getNumPoints()));
}
break;
case POLYGON:
{
int *l_ptrParts = NULL;
struct point *l_ptrPoints = NULL;
inp.read((char*)(pg+index),44);
l_ptrParts = new int[pg[index].getNumParts()];
l_ptrPoints = new struct point[pg[index].getNumPoints()];
pg[index].setParts(l_ptrParts);
pg[index].setPoints(l_ptrPoints);
inp.read((char*)l_ptrParts, (sizeof(int)*pg[index].getNumParts()));
inp.read((char*)l_ptrPoints, (sizeof(struct point)*pg[index].getNumPoints()));
}
break;
case MULTIPOINT:
{
struct point *l_ptrPoints = NULL;
inp.read((char*)(mp+index),40);
l_ptrPoints = new struct point[mp[index].getNumPoints()];
mp[index].setPoints(l_ptrPoints);
inp.read((char*)l_ptrPoints, (sizeof(struct point)*mp[index].getNumPoints()));
}
break;
default:
cout %26lt;%26lt; "\n The shape type " %26lt;%26lt; mh.getShapeType () %26lt;%26lt; " is not handled yet\n";
}
// Increment index to point to next shape object in the shape array
index ++;
}
inp.close();
}
/*************************************...
* getTotalShapes
* @return int Returns the total number of shapes in the shape file
**************************************...
int getTotalShapes()
{
ifstream inp;
RecordHeader rh;
int l_shapeCount = 0;
inp.open(FILENAME, ios::in, filebuf::openprot);
inp.setmode(filebuf::binary);
inp.seekg(100, ios::beg);
while(!inp.eof())
{
inp.read((char*)%26amp;rh,8);
if(inp.eof())
break;
inp.seekg(rh.getContentLength()*2, ios::cur);
l_shapeCount++;
}
inp.close();
return l_shapeCount;
}
Can someone convert the code to java...... !!!?
If you are still stuck, may be you can contact a java expert at websites like http://askexpert.info/ to help you finish your assignment.
Reply:go to rentacoder.com
pay some money and someone could do it for u
i think it will cost u about 10$
// ShapeFileReader.cpp: implementation of the ShapeFileReader class.
//////////////////////////////////////...
#include "iostream.h"
#include "fstream.h"
#include "ShapeFileReader.h"
#include "MainHeader.h"
#include "RecordHeader.h"
#include "Point.h"
#include "Polygon.h"
#include "MultiPoint.h"
#include "PolyLine.h"
const char* FILENAME = "c:/shapes/cities.shp";
int getTotalShapes();
MainHeader mh;
Point *pt;
MultiPoint *mp;
Polygon *pg;
PolyLine *pl;
void main()
{
RecordHeader rh;
ifstream inp;
int index=0;
int l_totalShapes = getTotalShapes();
inp.open(FILENAME,ios::in, filebuf::openprot);
inp.setmode(filebuf::binary);
inp.read((char*)%26amp;mh, 100);
cout %26lt;%26lt; "\n File Code = " %26lt;%26lt; mh.getFileCode();
cout %26lt;%26lt; "\n File Length = " %26lt;%26lt; mh.getFileLength();
cout %26lt;%26lt; "\n Version = " %26lt;%26lt; mh.getVersion();
cout %26lt;%26lt; "\n Shape Type = " %26lt;%26lt; mh.getShapeType();
cout %26lt;%26lt; "\n xMin = " %26lt;%26lt; mh.getXMin();
cout %26lt;%26lt; "\n yMin = " %26lt;%26lt; mh.getYMin();
cout %26lt;%26lt; "\n xMax = " %26lt;%26lt; mh.getXMax();
cout %26lt;%26lt; "\n yMax = " %26lt;%26lt; mh.getYMax();
cout %26lt;%26lt; "\n zMin = " %26lt;%26lt; mh.getZMin();
cout %26lt;%26lt; "\n zMax = " %26lt;%26lt; mh.getZMax();
cout %26lt;%26lt; "\n mMin = " %26lt;%26lt; mh.getMMin();
cout %26lt;%26lt; "\n mMax = " %26lt;%26lt; mh.getMMax();
cout %26lt;%26lt; "\n Total shapes = " %26lt;%26lt; l_totalShapes;
switch (mh.getShapeType())
{
case POINT:
pt = new Point[l_totalShapes];
break;
case POLYLINE:
pl = new PolyLine[l_totalShapes];
break;
case POLYGON:
pg = new Polygon[l_totalShapes];
break;
case MULTIPOINT:
mp = new MultiPoint[l_totalShapes];
break;
}
while (index %26lt; l_totalShapes)
{
inp.read((char*)%26amp;rh,8);
if(inp.eof())
break;
switch(mh.getShapeType())
{
case POINT:
inp.read((char*)(pt+index),20);
break;
case POLYLINE:
{
int *l_ptrParts = NULL;
struct point *l_ptrPoints = NULL;
inp.read((char*)(pl+index),44);
l_ptrParts = new int[pl[index].getNumParts()];
l_ptrPoints = new struct point[pl[index].getNumPoints()];
pl[index].setParts(l_ptrParts);
pl[index].setPoints(l_ptrPoints);
inp.read((char*)l_ptrParts, (sizeof(int)*pl[index].getNumParts()));
inp.read((char*)l_ptrPoints, (sizeof(struct point)*pl[index].getNumPoints()));
}
break;
case POLYGON:
{
int *l_ptrParts = NULL;
struct point *l_ptrPoints = NULL;
inp.read((char*)(pg+index),44);
l_ptrParts = new int[pg[index].getNumParts()];
l_ptrPoints = new struct point[pg[index].getNumPoints()];
pg[index].setParts(l_ptrParts);
pg[index].setPoints(l_ptrPoints);
inp.read((char*)l_ptrParts, (sizeof(int)*pg[index].getNumParts()));
inp.read((char*)l_ptrPoints, (sizeof(struct point)*pg[index].getNumPoints()));
}
break;
case MULTIPOINT:
{
struct point *l_ptrPoints = NULL;
inp.read((char*)(mp+index),40);
l_ptrPoints = new struct point[mp[index].getNumPoints()];
mp[index].setPoints(l_ptrPoints);
inp.read((char*)l_ptrPoints, (sizeof(struct point)*mp[index].getNumPoints()));
}
break;
default:
cout %26lt;%26lt; "\n The shape type " %26lt;%26lt; mh.getShapeType () %26lt;%26lt; " is not handled yet\n";
}
// Increment index to point to next shape object in the shape array
index ++;
}
inp.close();
}
/*************************************...
* getTotalShapes
* @return int Returns the total number of shapes in the shape file
**************************************...
int getTotalShapes()
{
ifstream inp;
RecordHeader rh;
int l_shapeCount = 0;
inp.open(FILENAME, ios::in, filebuf::openprot);
inp.setmode(filebuf::binary);
inp.seekg(100, ios::beg);
while(!inp.eof())
{
inp.read((char*)%26amp;rh,8);
if(inp.eof())
break;
inp.seekg(rh.getContentLength()*2, ios::cur);
l_shapeCount++;
}
inp.close();
return l_shapeCount;
}
Can someone convert the code to java...... !!!?
If you are still stuck, may be you can contact a java expert at websites like http://askexpert.info/ to help you finish your assignment.
Reply:go to rentacoder.com
pay some money and someone could do it for u
i think it will cost u about 10$
Plz explain me with this....?
content=//Program to demonstrate Deletion of an element in a Link List.
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;string.h%26gt;
struct abc
{
char n[20];
int m;
int p;
int c;
abc *next;
};
void main()
{
clrscr();
int c=0,per;
abc *list,*start=NULL,*ptr,*prev;
char nm[20],flag;
cout%26lt;%26lt;"enter the name and marks of three subjects of five children ";
for(int i=0;i%26lt;=4;i++)
{
if(start==NULL)
{
list=new abc;
cout%26lt;%26lt;"enter the details :";
cin%26gt;%26gt;list-%26gt;n%26gt;%26gt;list-%26gt;p%26gt;%26gt;list-%26gt;c%26gt;%26gt;list-%26gt;...
start=list;
}
else
{
ptr=new abc;
cin%26gt;%26gt;ptr-%26gt;n%26gt;%26gt;ptr-%26gt;p%26gt;%26gt;ptr-%26gt;c%26gt;%26gt;ptr-%26gt;m;
list-%26gt;next=ptr;
list=list-%26gt;next;
} }
// delete the record whose name is entered
cout%26lt;%26lt;"\n enter the name whose record is to be delete \n";
cin%26gt;%26gt;nm;
ptr=start;
cout%26lt;%26lt;"\n the list is :\n";
prev=ptr;
while(ptr!=NULL)//1
{
if(strcmp(ptr-%26gt;n,nm)==0)//3
{
flag='y';//4
cout%26lt;%26lt;"yes got the record ";//5
if (ptr==start)//6
start=ptr-%26gt;next;//7
else
prev-%26gt;next=ptr-%26gt;next;//9
if(ptr-%26gt;next==NULL)//10
prev-%26gt;next=NULL;//11
}
prev=ptr;//12
ptr=ptr-%26gt;next;//13
}//end of while
if(flag!='y')
{
cout%26lt;%26lt;"sorry no such name present \n";
c=4;
}
else
c=5;
//display all the records of the linked list
ptr=start;
cout%26lt;%26lt;"\n\n";
i=0;
cout%26lt;%26lt;"name percentage\n";
while(ptr!=NULL)
{ ++i;
cout%26lt;%26lt;"\n name :"%26lt;%26lt;ptr-%26gt;n;
cout%26lt;%26lt;" percent :"%26lt;%26lt;(ptr-%26gt;p+ptr-%26gt;c+ptr-%26gt;m)/3;
ptr=ptr-%26gt;next;
if (i==c)
break;
}
getch();
}
Plz explain me with this....?
huh?
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;string.h%26gt;
struct abc
{
char n[20];
int m;
int p;
int c;
abc *next;
};
void main()
{
clrscr();
int c=0,per;
abc *list,*start=NULL,*ptr,*prev;
char nm[20],flag;
cout%26lt;%26lt;"enter the name and marks of three subjects of five children ";
for(int i=0;i%26lt;=4;i++)
{
if(start==NULL)
{
list=new abc;
cout%26lt;%26lt;"enter the details :";
cin%26gt;%26gt;list-%26gt;n%26gt;%26gt;list-%26gt;p%26gt;%26gt;list-%26gt;c%26gt;%26gt;list-%26gt;...
start=list;
}
else
{
ptr=new abc;
cin%26gt;%26gt;ptr-%26gt;n%26gt;%26gt;ptr-%26gt;p%26gt;%26gt;ptr-%26gt;c%26gt;%26gt;ptr-%26gt;m;
list-%26gt;next=ptr;
list=list-%26gt;next;
} }
// delete the record whose name is entered
cout%26lt;%26lt;"\n enter the name whose record is to be delete \n";
cin%26gt;%26gt;nm;
ptr=start;
cout%26lt;%26lt;"\n the list is :\n";
prev=ptr;
while(ptr!=NULL)//1
{
if(strcmp(ptr-%26gt;n,nm)==0)//3
{
flag='y';//4
cout%26lt;%26lt;"yes got the record ";//5
if (ptr==start)//6
start=ptr-%26gt;next;//7
else
prev-%26gt;next=ptr-%26gt;next;//9
if(ptr-%26gt;next==NULL)//10
prev-%26gt;next=NULL;//11
}
prev=ptr;//12
ptr=ptr-%26gt;next;//13
}//end of while
if(flag!='y')
{
cout%26lt;%26lt;"sorry no such name present \n";
c=4;
}
else
c=5;
//display all the records of the linked list
ptr=start;
cout%26lt;%26lt;"\n\n";
i=0;
cout%26lt;%26lt;"name percentage\n";
while(ptr!=NULL)
{ ++i;
cout%26lt;%26lt;"\n name :"%26lt;%26lt;ptr-%26gt;n;
cout%26lt;%26lt;" percent :"%26lt;%26lt;(ptr-%26gt;p+ptr-%26gt;c+ptr-%26gt;m)/3;
ptr=ptr-%26gt;next;
if (i==c)
break;
}
getch();
}
Plz explain me with this....?
huh?
Project Help?
The question is:
I want to write a program on Client-server program using OLTP i.e., Online transaction processing Using Centralized solution, but I want to write a program on Fifo. what changes I have to make in the program to get a Fifo program.
%26lt;"OLTP" a client-server simulation%26gt;
File Name:server_oltp.c
Discription:Compile %26amp; Run as DEAMON PROCESS.
#include "oltp.h" /*This file contains all the header files needed for both Clint and Server*/
#define LOG_MSG_LEN 100
/*function prototypes*/
void send_chan(int,OLTP_MSG_BUFF);
void send_reply(int,int,int,OLTP_MSG_BUFF );
int is_acc(int,int);
void start_logging(void);
int chan_gen(int);
void dump_log(int);
/*Globle Variables*/
int nof_clints=0,dead_clint,log_d,clint_list...
char log_msg[LOG_MSG_LEN];
main(int argc,char *argv[])
{
int i,j,semd,msgd,mdf_d,ret,off,server_pid;
char def_choise[6],time_ch[30];
time_t local_time;
OLTP_MSG_BUFF msg_clint,msg_reply;
SB_ACC sb_acc;
struct msqid_ds msg_stat;
if(argc == 1)
{
printf("USAGE: %s install | start | stop\n",argv[0]);
exit(0);
}
if(strcmp(argv[1],"install")==0)
{
system("clear");
printf("\n##### WELCOME TO OLTP SERVER INSTALLATION.........press[X] to EXIT:");
i=getchar();
if(i == 'X' || i == 'x')
{
printf("\n\t\t\tABORTED BY USER ! !\n");
exit(0);
}
printf("\n\t\t\tCREATING Master Database File in ./MDF.dbase...");
mdf_d=open("./MDF.dbase",O_WRONLY | O_CREAT | O_EXCL,0666);
if(mdf_d %26lt; 0)
{
printf("\nMAY BE SERVER IS ALLREADY INSTALLED....remove MDF.dat then TRY AGAIN ! !\n");
exit(0);
}
printf("\n\t\t\tCREATING ADMINSTRATOR ACCOUNT........");
printf("\n\t\t\tadminstrator phone number:");
scanf("%d",%26amp;sb_acc.acc_ph);
off=sizeof(struct SB_ACC);
sb_acc.acc_no=1;sb_acc.balence=1000;
write(mdf_d,(char*)(%26amp;sb_acc),off);
close(mdf_d);
printf("\n\t\t\tSERVER INSTALLED SUSCCESSFULLY.......");
printf("\n\t\t\tNow You can start the server....[OK]\n");
getchar();
exit(0);
}
if(strcmp(argv[1],"stop")==0)
{
if((semd=semget(OLTP_SEMID,1,IPC_CRE... %26lt; 0)
{
printf("\n\t\t\tsemget() error......Server stop failed ! !\n");
exit(2);
}
semctl(semd,0,IPC_RMID,0);
if((msgd=msgget(OLTP_MSGID,IPC_CREAT... %26lt; 0)
{
printf("\n\t\t\tmsgget() error......Server stop failed ! !\n");
exit(2);
}
msgctl(msgd,IPC_RMID,%26amp;msg_stat);
exit(0);
}
if(strcmp(argv[1],"start")==0)
{
mdf_d=open("./MDF.dbase",O_RDWR);
if(mdf_d %26lt; 0)
{
printf("\n\t\t\tFailed open Master Database File........Server start failed ! !\n");
exit(2);
}
msgd=msgget(OLTP_MSGID,IPC_CREAT | IPC_EXCL);
semd=semget(OLTP_SEMID,1,IPC_CREAT | IPC_EXCL | 0666);
if(semd == 0 || msgd == 0)
{
printf("\n\t\t\tsemget() OR msgget() error.........Server start failed ! !\n");
}
if((j=semctl(semd,0,SETVAL,1)) %26lt; 0)
{
printf("\n\t\t\tsemctl() error......Server start failed ! !\n");
exit(5);
}
j=semctl(semd,0,GETVAL,0);
}
else
{
printf("USAGE: %s install/start/stop\n",argv[0]);
exit(1);
}
log_d=open("./OLTP_server.log",O_TRUN... | O_WRONLY | O_CREAT | O_SYNC);
system("clear");
sleep(1);
server_pid=fork();
if(server_pid %26lt; 0)
{
printf("\n\t\t\tfork() error.........Server start failed ! !\n");
exit(7);
}
if(server_pid %26gt; 0)
{
printf("\n\t\t\tServer started successfully with PID [%d]......\n",server_pid);
time(%26amp;local_time);
ctime_r(%26amp;local_time,time_ch);
printf("\n\t\t\tON:%s",time_ch);
printf("\n\t\t\t............server logs in ./OLTP_server.log\n");
printf("\n\t\t\t............USE $tail -f ./OLTP_server.log to see the logs [OK]\n");
exit(0);
}
close(1);
if(dup(log_d) %26lt; 0)
{
char err[44]="dup() error.........Server start failed ! !\n";
write(2,(char*)(err),44);
exit(9);
}
close(2);close(0);
setpgrp();
start_logging();
while(1)
{
ret=msgrcv(msgd,(struct msgbuf*)(%26amp;msg_clint),MSG_LEN,MASTER_CHAN ,IPC_NOWAIT);
if(ret %26gt; 0)
{
dump_log(sprintf(log_msg,"-----%26gt;Got chan_req from %d\n",msg_clint.pid));
send_chan(msgd,msg_clint);
}
for(i=0;i%26lt;=nof_clints;i++)
{
ret=msgrcv(msgd,(struct msgbuf*)(%26amp;msg_clint),MSG_LEN,i+2,IPC_NOW...
if(ret %26gt;= 0) send_reply(semd,msgd,mdf_d,msg_clint);
}
}/*infinite loop..hence deamon process*/
}
/*This function is to send a uniqe channel number to clients who request through MASTER CHANNEL*/
void send_chan(int msgd,OLTP_MSG_BUFF msg_clint)
{
int chan_no;
OLTP_MSG_BUFF msg_reply;
chan_no=chan_gen(msg_clint.pid);
if(chan_no %26gt; 0) nof_clints=nof_clints+1;
msg_reply.req_rep_info=chan_no;
msg_reply.mtype=msg_clint.pid;
dump_log(sprintf(log_msg,"-----%26gt;Sendi... chan %d to %d\n",msg_reply.req_rep_info,msg_clint.p...
msgsnd(msgd,(struct msgbuf*)(%26amp;msg_reply),MSG_LEN,0);
return;
}
/*End of function*/
/*This Function is to send reply to the client processes.The reply is sent through a que with client pid as
messege type.client PID as message type is only for the simplicity...In actual OLTP we should stick for
some other method*/
void send_reply(int semd,int msgd,int mdf_d,OLTP_MSG_BUFF msg_clint)
{
int i,off,new_acc_no,stat_mdf,how_many_acc;
time_t local_time;
char time_ch[30];
OLTP_MSG_BUFF msg_reply;
SB_ACC sb_acc;
struct msqid_ds msg_stat;
off=sizeof(struct SB_ACC);
switch(msg_clint.req_type)
{
case 1:
stat_mdf=lseek(mdf_d,0,SEEK_END);
how_many_acc=stat_mdf/off;
new_acc_no=how_many_acc+1;
sb_acc.acc_ph=msg_clint.req_rep_inf...
sb_acc.acc_no=new_acc_no;
sb_acc.balence=1000;
dump_log(sprintf(log_msg,"TRANSACTI... ON [%d]--%26gt;New acc[%d] is OPENED ! ! Whose Acc_ph[%d]\n",msg_clint.pid,sb_acc.acc_n...
write(mdf_d,(char *)(%26amp;sb_acc),sizeof(struct SB_ACC));
msg_reply.req_rep_info=sb_acc.acc_n...
break;
case 2:
lseek(mdf_d,0,0);
if(is_acc(mdf_d,msg_clint.acc_no) != 0)
{
msg_reply.req_rep_info=-2;
break;
}
off=(msg_clint.acc_no-1)*off;
lseek(mdf_d,off,0);
read(mdf_d,(char*)(%26amp;sb_acc),sizeof(... SB_ACC));
sb_acc.acc_ph=msg_clint.req_rep_inf...
lseek(mdf_d,off,0);
write(mdf_d,(char*)(%26amp;sb_acc),sizeof... SB_ACC));
msg_reply.req_rep_info=sb_acc.acc_p...
dump_log(sprintf(log_msg,"TRANSACTI... ON [%d]--%26gt;Acc no[%d] NOW have[%d] phone_no\n",msg_clint.pid,sb_acc.acc_no,...
break;
case 3:
lseek(mdf_d,0,0);
if(is_acc(mdf_d,msg_clint.acc_no) != 0)
{
msg_reply.req_rep_info=-3;
break;
}
off=(msg_clint.acc_no-1)*off;
lseek(mdf_d,off,0);
read(mdf_d,(char*)(%26amp;sb_acc),sizeof(... SB_ACC));
lseek(mdf_d,0,0);
msg_reply.acc_no=sb_acc.acc_ph;
msg_reply.req_rep_info=sb_acc.balen...
dump_log(sprintf(log_msg,"ACCOUNT [%d] INFORMATION IS SENT TO [%d]\n",sb_acc.acc_no,msg_clint.pid));
break;
case 4:
lseek(mdf_d,0,0);
if(is_acc(mdf_d,msg_clint.acc_no) != 0)
{
msg_reply.req_rep_info=-4;
break;
}
off=(msg_clint.acc_no-1)*off;
lseek(mdf_d,off,0);
read(mdf_d,(char*)(%26amp;sb_acc),sizeof(... SB_ACC));
sb_acc.balence=sb_acc.balence+msg_c...
lseek(mdf_d,off,0);
write(mdf_d,(char*)(%26amp;sb_acc),sizeof... SB_ACC));
msg_reply.req_rep_info=sb_acc.balen...
dump_log(sprintf(log_msg,"TRANSACTI... ON [%d]--%26gt;After debiting acc no %d now have %d balence no\n",msg_clint.pid,sb_acc.acc_no,sb_acc...
break;
case 5:
lseek(mdf_d,0,0);
if(is_acc(mdf_d,msg_clint.acc_no) != 0)
{
msg_reply.req_rep_info=-5;
break;
}
off=(msg_clint.acc_no-1)*off;
lseek(mdf_d,off,0);
read(mdf_d,(char*)(%26amp;sb_acc),sizeof(... SB_ACC));
if((sb_acc.balence-msg_clint.req_re... %26lt; 1000)
{
msg_reply.req_rep_info=-55;
break;
}
sb_acc.balence=sb_acc.balence-msg_c...
lseek(mdf_d,off,0);
write(mdf_d,(char*)(%26amp;sb_acc),sizeof... SB_ACC));
msg_reply.req_rep_info=sb_acc.balen...
dump_log(sprintf(log_msg,"TRANSACTI... ON [%d]--%26gt;After withdra acc no %d now have %d balence no\n",msg_clint.pid,sb_acc.acc_no,sb_acc...
break;
case 6:
clint_list[msg_clint.req_rep_info-2...
nof_clints=nof_clints-1;
msg_reply.req_rep_info=BYE;
dump_log(sprintf(log_msg,"-----%26gt;Cli... %d with PID[%d] LOGGED OUT ! !\n",msg_clint.req_rep_info,msg_clint.pi...
break;
case 7:
if(msg_clint.req_rep_info != OLTP_ADMIN_KEY)
{
dump_log(sprintf(log_msg,"-----%26gt;%d AUTHENTIFICATION FAILED ! !\n",msg_clint.pid));
msg_reply.req_rep_info=-7;
break;
}
dump_log(sprintf(log_msg,"-----%26gt;%d AS ADMINSTRATOR IS GOING TO SHUTTINGDOWN THE SERVER ! !\n",msg_clint.pid));
msg_reply.mtype=msg_clint.pid;
msg_reply.req_rep_info=AUTH_ADMIN;
msgsnd(msgd,(struct msgbuf*)(%26amp;msg_reply),MSG_LEN,0);
dump_log(sprintf(log_msg,"-----%26gt;OLT... SERVER DOWN\n"));
time(%26amp;local_time);
ctime_r(%26amp;local_time,time_ch);
dump_log(sprintf(log_msg,"-----%26gt;ON %s",time_ch));
dump_log(sprintf(log_msg,"#########... ANY QUESTIONS TO %26lt;mdshreenath@yahoo.com%26gt; ###############\n"));
close(log_d);close(mdf_d);
sleep(5);
semctl(semd,0,IPC_RMID,0);
msgctl(msgd,IPC_RMID,%26amp;msg_stat);
exit(0);
default:
printf("wrong CHOISE ! ! !\n");
return;
}
msg_reply.mtype=msg_clint.pid;
if((msgsnd(msgd,(struct msgbuf*)(%26amp;msg_reply),MSG_LEN,0)) %26lt; 0)
{
printf("msgsnd() error.........Failed to send REPLY ! !\n");
exit(6);
};
}
/*This function is to check for valid account number*/
int is_acc(int mdf_d,int acc_no)
{
int off,stat_mdf,how_many_acc;
SB_ACC acc;
off=sizeof(struct SB_ACC);
stat_mdf=lseek(mdf_d,0,SEEK_END);
how_many_acc=stat_mdf/off;
if(acc_no %26gt; how_many_acc) return(-1);
return(0);
}
/*This function dumps some innitial messeges to log file*/
void start_logging(void)
{
time_t local_time;
char time_ch[30];
dump_log(sprintf(log_msg,"###########... LOG FILE GENERATED BY OLTP SERVER #####################\n"));
time(%26amp;local_time);
ctime_r(%26amp;local_time,time_ch);
dump_log(sprintf(log_msg,"-----%26gt;ON %s",time_ch));
dump_log(sprintf(log_msg,"-----%26gt;Serve... started successfully.......with PID [%d]\n",getpid()));
return;
}
/*This function is to get a uniq channel number*/
int chan_gen(int pid)
{
int i;
for(i=0;i%26lt;MAX_NO_CLINTS;i++)
{
if(clint_list[i] == 0)
{
clint_list[i]=pid;
return(i+2);/*because chan 1 is for MASTER*/
}
}
return(-1);
}
/*This function is to dump logs to log file */
void dump_log(int size)
{
if(size %26lt; 0) return;
write(log_d,log_msg,size);
return;
}
/*Physical End*/
Project Help?
Join a programming forum or newsgroup.
I want to write a program on Client-server program using OLTP i.e., Online transaction processing Using Centralized solution, but I want to write a program on Fifo. what changes I have to make in the program to get a Fifo program.
%26lt;"OLTP" a client-server simulation%26gt;
File Name:server_oltp.c
Discription:Compile %26amp; Run as DEAMON PROCESS.
#include "oltp.h" /*This file contains all the header files needed for both Clint and Server*/
#define LOG_MSG_LEN 100
/*function prototypes*/
void send_chan(int,OLTP_MSG_BUFF);
void send_reply(int,int,int,OLTP_MSG_BUFF );
int is_acc(int,int);
void start_logging(void);
int chan_gen(int);
void dump_log(int);
/*Globle Variables*/
int nof_clints=0,dead_clint,log_d,clint_list...
char log_msg[LOG_MSG_LEN];
main(int argc,char *argv[])
{
int i,j,semd,msgd,mdf_d,ret,off,server_pid;
char def_choise[6],time_ch[30];
time_t local_time;
OLTP_MSG_BUFF msg_clint,msg_reply;
SB_ACC sb_acc;
struct msqid_ds msg_stat;
if(argc == 1)
{
printf("USAGE: %s install | start | stop\n",argv[0]);
exit(0);
}
if(strcmp(argv[1],"install")==0)
{
system("clear");
printf("\n##### WELCOME TO OLTP SERVER INSTALLATION.........press[X] to EXIT:");
i=getchar();
if(i == 'X' || i == 'x')
{
printf("\n\t\t\tABORTED BY USER ! !\n");
exit(0);
}
printf("\n\t\t\tCREATING Master Database File in ./MDF.dbase...");
mdf_d=open("./MDF.dbase",O_WRONLY | O_CREAT | O_EXCL,0666);
if(mdf_d %26lt; 0)
{
printf("\nMAY BE SERVER IS ALLREADY INSTALLED....remove MDF.dat then TRY AGAIN ! !\n");
exit(0);
}
printf("\n\t\t\tCREATING ADMINSTRATOR ACCOUNT........");
printf("\n\t\t\tadminstrator phone number:");
scanf("%d",%26amp;sb_acc.acc_ph);
off=sizeof(struct SB_ACC);
sb_acc.acc_no=1;sb_acc.balence=1000;
write(mdf_d,(char*)(%26amp;sb_acc),off);
close(mdf_d);
printf("\n\t\t\tSERVER INSTALLED SUSCCESSFULLY.......");
printf("\n\t\t\tNow You can start the server....[OK]\n");
getchar();
exit(0);
}
if(strcmp(argv[1],"stop")==0)
{
if((semd=semget(OLTP_SEMID,1,IPC_CRE... %26lt; 0)
{
printf("\n\t\t\tsemget() error......Server stop failed ! !\n");
exit(2);
}
semctl(semd,0,IPC_RMID,0);
if((msgd=msgget(OLTP_MSGID,IPC_CREAT... %26lt; 0)
{
printf("\n\t\t\tmsgget() error......Server stop failed ! !\n");
exit(2);
}
msgctl(msgd,IPC_RMID,%26amp;msg_stat);
exit(0);
}
if(strcmp(argv[1],"start")==0)
{
mdf_d=open("./MDF.dbase",O_RDWR);
if(mdf_d %26lt; 0)
{
printf("\n\t\t\tFailed open Master Database File........Server start failed ! !\n");
exit(2);
}
msgd=msgget(OLTP_MSGID,IPC_CREAT | IPC_EXCL);
semd=semget(OLTP_SEMID,1,IPC_CREAT | IPC_EXCL | 0666);
if(semd == 0 || msgd == 0)
{
printf("\n\t\t\tsemget() OR msgget() error.........Server start failed ! !\n");
}
if((j=semctl(semd,0,SETVAL,1)) %26lt; 0)
{
printf("\n\t\t\tsemctl() error......Server start failed ! !\n");
exit(5);
}
j=semctl(semd,0,GETVAL,0);
}
else
{
printf("USAGE: %s install/start/stop\n",argv[0]);
exit(1);
}
log_d=open("./OLTP_server.log",O_TRUN... | O_WRONLY | O_CREAT | O_SYNC);
system("clear");
sleep(1);
server_pid=fork();
if(server_pid %26lt; 0)
{
printf("\n\t\t\tfork() error.........Server start failed ! !\n");
exit(7);
}
if(server_pid %26gt; 0)
{
printf("\n\t\t\tServer started successfully with PID [%d]......\n",server_pid);
time(%26amp;local_time);
ctime_r(%26amp;local_time,time_ch);
printf("\n\t\t\tON:%s",time_ch);
printf("\n\t\t\t............server logs in ./OLTP_server.log\n");
printf("\n\t\t\t............USE $tail -f ./OLTP_server.log to see the logs [OK]\n");
exit(0);
}
close(1);
if(dup(log_d) %26lt; 0)
{
char err[44]="dup() error.........Server start failed ! !\n";
write(2,(char*)(err),44);
exit(9);
}
close(2);close(0);
setpgrp();
start_logging();
while(1)
{
ret=msgrcv(msgd,(struct msgbuf*)(%26amp;msg_clint),MSG_LEN,MASTER_CHAN ,IPC_NOWAIT);
if(ret %26gt; 0)
{
dump_log(sprintf(log_msg,"-----%26gt;Got chan_req from %d\n",msg_clint.pid));
send_chan(msgd,msg_clint);
}
for(i=0;i%26lt;=nof_clints;i++)
{
ret=msgrcv(msgd,(struct msgbuf*)(%26amp;msg_clint),MSG_LEN,i+2,IPC_NOW...
if(ret %26gt;= 0) send_reply(semd,msgd,mdf_d,msg_clint);
}
}/*infinite loop..hence deamon process*/
}
/*This function is to send a uniqe channel number to clients who request through MASTER CHANNEL*/
void send_chan(int msgd,OLTP_MSG_BUFF msg_clint)
{
int chan_no;
OLTP_MSG_BUFF msg_reply;
chan_no=chan_gen(msg_clint.pid);
if(chan_no %26gt; 0) nof_clints=nof_clints+1;
msg_reply.req_rep_info=chan_no;
msg_reply.mtype=msg_clint.pid;
dump_log(sprintf(log_msg,"-----%26gt;Sendi... chan %d to %d\n",msg_reply.req_rep_info,msg_clint.p...
msgsnd(msgd,(struct msgbuf*)(%26amp;msg_reply),MSG_LEN,0);
return;
}
/*End of function*/
/*This Function is to send reply to the client processes.The reply is sent through a que with client pid as
messege type.client PID as message type is only for the simplicity...In actual OLTP we should stick for
some other method*/
void send_reply(int semd,int msgd,int mdf_d,OLTP_MSG_BUFF msg_clint)
{
int i,off,new_acc_no,stat_mdf,how_many_acc;
time_t local_time;
char time_ch[30];
OLTP_MSG_BUFF msg_reply;
SB_ACC sb_acc;
struct msqid_ds msg_stat;
off=sizeof(struct SB_ACC);
switch(msg_clint.req_type)
{
case 1:
stat_mdf=lseek(mdf_d,0,SEEK_END);
how_many_acc=stat_mdf/off;
new_acc_no=how_many_acc+1;
sb_acc.acc_ph=msg_clint.req_rep_inf...
sb_acc.acc_no=new_acc_no;
sb_acc.balence=1000;
dump_log(sprintf(log_msg,"TRANSACTI... ON [%d]--%26gt;New acc[%d] is OPENED ! ! Whose Acc_ph[%d]\n",msg_clint.pid,sb_acc.acc_n...
write(mdf_d,(char *)(%26amp;sb_acc),sizeof(struct SB_ACC));
msg_reply.req_rep_info=sb_acc.acc_n...
break;
case 2:
lseek(mdf_d,0,0);
if(is_acc(mdf_d,msg_clint.acc_no) != 0)
{
msg_reply.req_rep_info=-2;
break;
}
off=(msg_clint.acc_no-1)*off;
lseek(mdf_d,off,0);
read(mdf_d,(char*)(%26amp;sb_acc),sizeof(... SB_ACC));
sb_acc.acc_ph=msg_clint.req_rep_inf...
lseek(mdf_d,off,0);
write(mdf_d,(char*)(%26amp;sb_acc),sizeof... SB_ACC));
msg_reply.req_rep_info=sb_acc.acc_p...
dump_log(sprintf(log_msg,"TRANSACTI... ON [%d]--%26gt;Acc no[%d] NOW have[%d] phone_no\n",msg_clint.pid,sb_acc.acc_no,...
break;
case 3:
lseek(mdf_d,0,0);
if(is_acc(mdf_d,msg_clint.acc_no) != 0)
{
msg_reply.req_rep_info=-3;
break;
}
off=(msg_clint.acc_no-1)*off;
lseek(mdf_d,off,0);
read(mdf_d,(char*)(%26amp;sb_acc),sizeof(... SB_ACC));
lseek(mdf_d,0,0);
msg_reply.acc_no=sb_acc.acc_ph;
msg_reply.req_rep_info=sb_acc.balen...
dump_log(sprintf(log_msg,"ACCOUNT [%d] INFORMATION IS SENT TO [%d]\n",sb_acc.acc_no,msg_clint.pid));
break;
case 4:
lseek(mdf_d,0,0);
if(is_acc(mdf_d,msg_clint.acc_no) != 0)
{
msg_reply.req_rep_info=-4;
break;
}
off=(msg_clint.acc_no-1)*off;
lseek(mdf_d,off,0);
read(mdf_d,(char*)(%26amp;sb_acc),sizeof(... SB_ACC));
sb_acc.balence=sb_acc.balence+msg_c...
lseek(mdf_d,off,0);
write(mdf_d,(char*)(%26amp;sb_acc),sizeof... SB_ACC));
msg_reply.req_rep_info=sb_acc.balen...
dump_log(sprintf(log_msg,"TRANSACTI... ON [%d]--%26gt;After debiting acc no %d now have %d balence no\n",msg_clint.pid,sb_acc.acc_no,sb_acc...
break;
case 5:
lseek(mdf_d,0,0);
if(is_acc(mdf_d,msg_clint.acc_no) != 0)
{
msg_reply.req_rep_info=-5;
break;
}
off=(msg_clint.acc_no-1)*off;
lseek(mdf_d,off,0);
read(mdf_d,(char*)(%26amp;sb_acc),sizeof(... SB_ACC));
if((sb_acc.balence-msg_clint.req_re... %26lt; 1000)
{
msg_reply.req_rep_info=-55;
break;
}
sb_acc.balence=sb_acc.balence-msg_c...
lseek(mdf_d,off,0);
write(mdf_d,(char*)(%26amp;sb_acc),sizeof... SB_ACC));
msg_reply.req_rep_info=sb_acc.balen...
dump_log(sprintf(log_msg,"TRANSACTI... ON [%d]--%26gt;After withdra acc no %d now have %d balence no\n",msg_clint.pid,sb_acc.acc_no,sb_acc...
break;
case 6:
clint_list[msg_clint.req_rep_info-2...
nof_clints=nof_clints-1;
msg_reply.req_rep_info=BYE;
dump_log(sprintf(log_msg,"-----%26gt;Cli... %d with PID[%d] LOGGED OUT ! !\n",msg_clint.req_rep_info,msg_clint.pi...
break;
case 7:
if(msg_clint.req_rep_info != OLTP_ADMIN_KEY)
{
dump_log(sprintf(log_msg,"-----%26gt;%d AUTHENTIFICATION FAILED ! !\n",msg_clint.pid));
msg_reply.req_rep_info=-7;
break;
}
dump_log(sprintf(log_msg,"-----%26gt;%d AS ADMINSTRATOR IS GOING TO SHUTTINGDOWN THE SERVER ! !\n",msg_clint.pid));
msg_reply.mtype=msg_clint.pid;
msg_reply.req_rep_info=AUTH_ADMIN;
msgsnd(msgd,(struct msgbuf*)(%26amp;msg_reply),MSG_LEN,0);
dump_log(sprintf(log_msg,"-----%26gt;OLT... SERVER DOWN\n"));
time(%26amp;local_time);
ctime_r(%26amp;local_time,time_ch);
dump_log(sprintf(log_msg,"-----%26gt;ON %s",time_ch));
dump_log(sprintf(log_msg,"#########... ANY QUESTIONS TO %26lt;mdshreenath@yahoo.com%26gt; ###############\n"));
close(log_d);close(mdf_d);
sleep(5);
semctl(semd,0,IPC_RMID,0);
msgctl(msgd,IPC_RMID,%26amp;msg_stat);
exit(0);
default:
printf("wrong CHOISE ! ! !\n");
return;
}
msg_reply.mtype=msg_clint.pid;
if((msgsnd(msgd,(struct msgbuf*)(%26amp;msg_reply),MSG_LEN,0)) %26lt; 0)
{
printf("msgsnd() error.........Failed to send REPLY ! !\n");
exit(6);
};
}
/*This function is to check for valid account number*/
int is_acc(int mdf_d,int acc_no)
{
int off,stat_mdf,how_many_acc;
SB_ACC acc;
off=sizeof(struct SB_ACC);
stat_mdf=lseek(mdf_d,0,SEEK_END);
how_many_acc=stat_mdf/off;
if(acc_no %26gt; how_many_acc) return(-1);
return(0);
}
/*This function dumps some innitial messeges to log file*/
void start_logging(void)
{
time_t local_time;
char time_ch[30];
dump_log(sprintf(log_msg,"###########... LOG FILE GENERATED BY OLTP SERVER #####################\n"));
time(%26amp;local_time);
ctime_r(%26amp;local_time,time_ch);
dump_log(sprintf(log_msg,"-----%26gt;ON %s",time_ch));
dump_log(sprintf(log_msg,"-----%26gt;Serve... started successfully.......with PID [%d]\n",getpid()));
return;
}
/*This function is to get a uniq channel number*/
int chan_gen(int pid)
{
int i;
for(i=0;i%26lt;MAX_NO_CLINTS;i++)
{
if(clint_list[i] == 0)
{
clint_list[i]=pid;
return(i+2);/*because chan 1 is for MASTER*/
}
}
return(-1);
}
/*This function is to dump logs to log file */
void dump_log(int size)
{
if(size %26lt; 0) return;
write(log_d,log_msg,size);
return;
}
/*Physical End*/
Project Help?
Join a programming forum or newsgroup.
Project help.?
I want to write a program on Client-server program using OLTP i.e., Online transaction processing. Using Decentralized solution, But the answer is in windows C, but I want it in Unix C,Can You please help by making changes in this program. Since I am not getting the output.
/*
%26lt;"OLTP" a client-server simulation%26gt;
File Name:client_oltp.c
Discription:Compile %26amp; Run as CLIENT PROCESS.
*/
#include "oltp.h" /*This file contains all the header files needed for both Client and Server*/
/*Function prototypes*/
int chan_req(int,int);
OLTP_MSG_BUFF send_msg(int,int,OLTP_MSG_BUFF);
void print_mdf(void);
void print_error(int);
void print_oltp(void);
int valid_choice(char);
int getint(void);
/*Globle variables*/
int MAX_Y,MAX_X;
time_t LOCAL_TIME;
char TIME_STRING[30];
main()
{
int semd,msgd,i,j,acc_ph,acc_no,amount,pid,a...
chtype key,user_choice;
time_t local_time;
char time_string[30];
OLTP_MSG_BUFF master_req,req_msg,reply_msg;
initscr();
getmaxyx(stdscr,MAX_Y,MAX_X);
keypad(stdscr,TRUE);
raw();
echo();
attron(A_REVERSE);
printw("\n WELCOME TO OLTP--A CLIENT SERVER SIMULATION BY %26lt;mdshreenath@yahoo.com%26gt; \n\n");
sleep(1);
refresh();
attroff(A_REVERSE);
semd=semget(OLTP_SEMID,1,0);
if(semd %26lt;0)
{
printw("\n\t\t\tFailed semget().........Restart the Server ! !\n");
refresh();
getch();
endwin();
exit(1);
}
msgd=msgget(OLTP_MSGID,0);
if(msgd %26lt; 0)
{
printw("\n\t\t\tFailed msgget().........Restart the Server ! !\n");
semctl(semd,0,IPC_RMID,0);
refresh();
getch();
endwin();
exit(2);
}
req_msg.mtype=chan_req(msgd,semd);
time(%26amp;LOCAL_TIME);
ctime_r(%26amp;LOCAL_TIME,TIME_STRING);
TIME_STRING[24]='\0';
printw("\n\t\t\tStarted ON:");
refresh();
attron(A_DIM);
printw("%s\n\n",TIME_STRING);
refresh();
attroff(A_DIM);
printw("\n\t\t\tPRESS [ENTER] to continue...........");
refresh();
getch();
print_oltp();refresh();
req_msg.pid=pid=getpid();
while(1)
{
printw("\n\tPRESS\n");
printw("\t\t\tc:Create A New Account\n");
printw("\t\t\te:Edit Existing Account\n");
printw("\t\t\tv:View Account Information\n");
printw("\t\t\td:Deposite To Existing Account\n");
printw("\t\t\tw:Withdraw From Existing Account\n");
printw("\t\t\tx:Transactions OVER...Want to eXit ! !\n");
printw("\t\t\ta:Adminstration\n");
printw("\n\tCHOICE");
refresh();
attron(A_BLINK);
printw(":");
attroff(A_BLINK);
refresh();
noecho();
user_choice=getch();
if(user_choice == 27) user_choice='x';
else if(!valid_choice(user_choice))
{
attron(A_BLINK);
addch(user_choice);
attroff(A_BLINK);
refresh();
attron(A_DIM);
printw("--INVALID CHOICE");
refresh();
beep();
sleep(1);
attroff(A_DIM);
print_oltp();
continue;
}
echo();
IP_AGAIN: print_oltp();
refresh();
switch(user_choice)
{
case 'c':
attron(A_DIM);printw("\n\t\t\tYou Are about to CREAT new Account\n");
refresh();
attroff(A_DIM);
printw("\n\t\t\tAccount Payee Phone Number:");
refresh();
acc_ph=getint();
if(acc_ph%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tCONFIRM.. [Y/N] :");
refresh();
key=getch();
if(key == 'n' || key == 27) goto IP_AGAIN;
req_msg.acc_no=0;
req_msg.req_type=1;
req_msg.req_rep_info=acc_ph;
reply_msg=send_msg(msgd,1,req_msg)...
if(reply_msg.req_rep_info %26lt; 0)
{
print_error(reply_msg.req_rep_inf...
getch();
print_oltp();
continue;
}
attron(A_REVERSE);
printw("\n New Account Created !! #Acc_no:%d Having #Acc_ph:%d ",reply_msg.req_rep_info,acc_ph);
refresh();
attroff(A_REVERSE);
attron(A_DIM | A_BLINK);
printw("\n\npress [ENTER]");
refresh();
attroff(A_DIM | A_BLINK);
getch();
break;
case 'e':
attron(A_DIM);
printw("\n\t\t\tYou are about to EDIT an account\n");
refresh();
attroff(A_DIM);
printw("\n\t\t\tAccount Number:");
refresh();
acc_no=getint();
if(acc_no%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tNew Tel_No:");
acc_ph=getint();
if(acc_ph%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tCINFIRM... [Y/N]:",acc_no,acc_ph);
refresh();
key=getch();
if(key == 'n') goto IP_AGAIN;
req_msg.acc_no=acc_no;
req_msg.req_type=2;
req_msg.req_rep_info=acc_ph;
reply_msg=send_msg(msgd,2,req_msg)...
if(reply_msg.req_rep_info %26lt; 0)
{
print_error(reply_msg.req_rep_inf...
getch();
print_oltp();
continue;
}
attron(A_REVERSE);
printw("\n Account Edited !! #Acc_no:%d #New Acc_ph:%d ",acc_no,reply_msg.req_rep_info);
refresh();
attroff(A_REVERSE);
attron(A_DIM | A_BLINK);
printw("\n\npress [ENTER]");
refresh();
attroff(A_DIM | A_BLINK);
getch();
break;
case 'v':
attron(A_DIM);
printw("\n\t\t\tYou are about to VIEW an acount information\n");
attroff(A_DIM);
printw("\n\t\t\tAccount Number:");
refresh();
acc_no=getint();
if(acc_no%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tCONFIRM...[Y/N]:",...
refresh();
key=getch();
if(key == 'n' || key == 27) goto IP_AGAIN;
req_msg.acc_no=acc_no;
req_msg.req_type=3;
req_msg.req_rep_info=acc_no;
reply_msg=send_msg(msgd,3,req_msg)...
if(reply_msg.req_rep_info %26lt; 0)
{
print_error(reply_msg.req_rep_inf...
getch();
print_oltp();
continue;
}
attron(A_DIM);
printw("\n\t\t\t------------------...
printw("\n\t\t\tAccount No:%d",acc_no);
printw("\n\t\t\tTelephone No:%d",reply_msg.acc_no);
printw("\n\t\t\tCurrent Balence:%d",reply_msg.req_rep_info);
printw("\n\t\t\t------------------...
attron(A_BLINK);printw("\n\n\t\t\t... [ENTER]");
refresh();
attroff(A_DIM | A_BLINK);
getch();
break;
case 'd':
attron(A_DIM);
printw("\n\t\t\tYou are about to DEPOSITE\n");
attroff(A_DIM);
refresh();
printw("\n\t\t\tAccount Number:");
refresh();
acc_no=getint();
if(acc_no%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tDebit:");
refresh();
amount=getint();
if(amount%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tCONFIRM... [Y/N]:",amount,acc_no);
refresh();
key=getch();
if(key == 'n' || key == 27) goto IP_AGAIN;
req_msg.acc_no=acc_no;
req_msg.req_type=4;
req_msg.req_rep_info=amount;
reply_msg=send_msg(msgd,4,req_msg)...
if(reply_msg.req_rep_info %26lt; 0)
{
print_error(reply_msg.req_rep_inf...
getch();
print_oltp();
continue;
}
attron(A_REVERSE);
printw("\n Debited!! #Acc_no:%d Now Has #Ballence:%d ",acc_no,reply_msg.req_rep_info);
refresh();
attroff(A_REVERSE);
attron(A_DIM | A_BLINK);
printw("\n\npress [ENTER]");
refresh();
attroff(A_BLINK | A_DIM);
getch();
break;
case 'w':
attron(A_DIM);
printw("\n\t\t\tYou are about to WITHDRAW\n");
refresh();
attroff(A_DIM);
printw("\n\t\t\tAccount Number:");
refresh();
acc_no=getint();
if(acc_no%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tWithdraw:");
refresh();
amount=getint();
if(amount%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tCONFIRM...[Y/N]:",...
refresh();
key=getch();
if(key == 'n' || key == 27) goto IP_AGAIN;
req_msg.acc_no=acc_no;
req_msg.req_type=5;
req_msg.req_rep_info=amount;
reply_msg=send_msg(msgd,5,req_msg)...
if(reply_msg.req_rep_info %26lt; 0)
{
print_error(reply_msg.req_rep_inf...
getch();
print_oltp();
continue;
}
attron(A_REVERSE);
printw(" Withdrawn !! #Acc_no:%d Now Has #Balence:%d ",acc_no,reply_msg.req_rep_info);
refresh();
attroff(A_REVERSE);
attron(A_DIM | A_BLINK);
printw("\n\npress [ENTER]");
refresh();
attroff(A_DIM | A_BLINK);
getch();
break;
case 'x':
attron(A_DIM);
printw("\n\t\t\tYOU ARE ABOUT TO EXIT\n\n");
refresh();
attroff(A_DIM);
printw("\n\t\t\tCONFIRM EXIT[Y/N]:");
refresh();
key=getch();
if(key == 'Y' || key == 'y')
{
req_msg.req_type=6;
req_msg.req_rep_info=req_msg.mtyp...
reply_msg=send_msg(msgd,6,req_msg...
if(reply_msg.req_rep_info == BYE)
{
printw("\n\t\t\tLogged OUT ON:");
refresh();
time(%26amp;local_time);
ctime_r(%26amp;local_time,time_string)...
attron(A_DIM);printw("%s\n",time...
refresh();
attroff(A_DIM);
}
else
{
printw("\n\t\t\tAbnormal EXIT ! !");
refresh();
}
sleep(1);
attron(A_BOLD);
printw("\n\t\t\tDO YOU WANT GENERATE ALL ACCOUNTS INFORMATION [Y/N]:");
refresh();
key=getch();
attroff(A_BOLD);
if(key == 'y') print_mdf();
attron(A_DIM);
printw("\nThanks FOR TRYING OLTP ! !");
printw("\nANY BUGS TO %26lt;");refresh();
attroff(A_DIM);
attron(A_BLINK);
printw("mdshreenath@yahoo.com");
refresh();
attroff(A_BLINK);
attron(A_DIM);
printw("%26gt;");
refresh();
attroff(A_DIM);
getch();
endwin();
exit(0);
}
print_oltp();
continue;
case 'a':
attron(A_BOLD);
printw("\n\t\t\t[YOU ARE ABOUT TO SHUTDOWN THE SERVER...]\n\n");
printw("\n\t\t\tWANT TO CONTINUE [Y/N]:");
attroff(A_BOLD);
refresh();
key=getch();
if(key != 'y')
{
print_oltp();
continue;
}
printw("\n\t\t\tADMIN KEY:");
refresh();
noecho();
refresh();
scanw("%d",%26amp;admin_key);
echo();
req_msg.req_type=7;
req_msg.req_rep_info=admin_key;
reply_msg=send_msg(msgd,7,req_msg)...
if(reply_msg.req_rep_info %26lt; 0)
{
print_error(reply_msg.req_rep_inf...
getch();
print_oltp();
continue;
}
clear();
print_oltp();
attron(A_BOLD);
printw("\n\t\t\tAS ADMINSTRATOR.....ON: ");
refresh();
attroff(A_BOLD);
time(%26amp;local_time);
ctime_r(%26amp;local_time,time_string);
attron(A_DIM);
printw("%s\n",time_string);refresh...
attroff(A_DIM);
sleep(1);
printw("\n\t\t\tDO YOU WANT GENERATE ALL ACCOUNTS INFORMATION..[Y/N]:");
refresh();
attroff(A_BOLD);
key=getch();
if(key == 'y') print_mdf();
attron(A_DIM);
printw("\nThanks FOR TRYING OLTP ! !");
printw("\nANY BUGS TO %26lt;");refresh();
attroff(A_DIM);
attron(A_BLINK);
printw("mdshreenath@yahoo.com");
refresh();
attroff(A_BLINK);
attron(A_DIM);
printw("%26gt;");
refresh();
attroff(A_DIM);
getch();
endwin();
exit(0);
default:
printw("\n\t\t\t");
attron(A_BOLD | A_BLINK | A_REVERSE);
printw("Wrong Choise");
refresh();
attroff(A_BOLD | A_BLINK | A_REVERSE);
getch();
print_oltp();
continue;
}/*End of Switch*/
print_oltp();
}/*infinite loop end*/
endwin();
}
/*This function is to send message to server through a channel number got using chan_req() function
This function returns reply message*/
OLTP_MSG_BUFF send_msg(int msgd,int msg_type,OLTP_MSG_BUFF req_msg)
{
int pid,nof_try=0;
char key;
OLTP_MSG_BUFF reply_msg;
printw("\n\t\t\tComunicating with the server...\n");
refresh();
while(msgsnd(msgd,(struct msgbuf*)(%26amp;req_msg),MSG_LEN,IPC_NOWAIT) %26lt; 0)
{
sleep(1);
nof_try++;
if(nof_try %26lt; 3) continue;
printw("\n\t\t\tServer NOT responding...TRY AGAIN [Y/N]:");
refresh();
key=getch();
if(key == 'N' || key == 'n')
{
printw("\n\t\t\tRestart the server.....\n");
refresh();
getch();
endwin();
exit(3);
}
}
pid=getpid();
nof_try=0;
while(msgrcv(msgd,(struct msgbuf*)(%26amp;reply_msg),MSG_LEN,pid,IPC_NOW... %26lt; 0)
{
sleep(1);
nof_try++;
if(nof_try %26lt; 3) continue;
printw("\n\t\t\tServer NOT responding...TRY AGAIN [Y/N]:");
refresh();
key=getch();
if(key == 'N' || key == 'n')
{
printw("\n\t\t\tRestart the server.....\n");
refresh();
getch();
endwin();
exit(4);
}
}
sleep(2);
printw("\n\t\t\t.....[DONE]\n");
refresh();
return(reply_msg);
}
/*This function is to requst the server process through MASTER CHANNEL for a uniq channel for
the future communication*/
int chan_req(int msgd,int semd)
{
int ret,key,nof_try=0;
OLTP_MSG_BUFF req_msg,reply_msg;
struct sembuf sops;
int pid;
pid=getpid();
req_msg.mtype=MASTER_CHAN;
req_msg.pid=getpid();
req_msg.acc_no=0;
req_msg.req_type=0;
req_msg.req_rep_info=getpid();
printw("\n\t\t\tRequesting Chanel for Communication...\n");
refresh();
sops.sem_num=0;
sops.sem_op=-1;
sops.sem_flg=0;
if(semop(semd,%26amp;sops,1) %26lt; 0)
{
printw("\n\t\t\tsemop failed ! !");
refresh();
getch();
endwin();
exit(1);
}
while(msgsnd(msgd,(struct msgbuf*)(%26amp;req_msg),MSG_LEN,IPC_NOWAIT) %26lt; 0)
{
sleep(1);
nof_try++;
if(nof_try %26lt; 3) continue;
printw("\n\t\t\tServer NOT responding...TRY AGAIN [Y/N]:");
refresh();
key=getch();
if(key == 'N' || key == 'n')
{
printw("\n\t\t\tRestart the server.....\n");
refresh();
sops.sem_op=1;
semop(semd,%26amp;sops,1);
getch();
endwin();
exit(2);
}
}
nof_try=0;
while(ret=msgrcv(msgd,(struct msgbuf*)(%26amp;reply_msg),MSG_LEN,pid,IPC_NOW... %26lt; 0)
{
sleep(1);
nof_try++;
if(nof_try %26lt; 3) continue;
printw("\n\t\t\tServer NOT responding...TRY AGAIN [Y/N]:");
refresh();
key=getch();
if(key == 'N' || key == 'n')
{
printw("\n\t\t\tRestart the server.....\n");
refresh();
sops.sem_op=1;
semop(semd,%26amp;sops,1);
getch();
endwin();
exit(2);
}
}
sops.sem_op=1;
semop(semd,%26amp;sops,1);
printw("\n\t\t\t.....GOT Chanel %d\n",reply_msg.req_rep_info);
refresh();
return(reply_msg.req_rep_info);
}
/*This function is to print the Master Data Base file in READABLE format*/
void print_mdf(void)
{
int off,mdf_d,i=1;
time_t local_time;
char time_ch[30];
FILE *acc_fd;
SB_ACC sb_acc;
mdf_d=open("./MDF.dbase",O_RDONLY);
acc_fd=fopen("./Accounts.txt","w");
if(acc_fd == NULL)
{
printw("\n\t\t\tERROR opening ./Accounts.txt\n");
return;
}
off=sizeof(struct SB_ACC);
lseek(mdf_d,0,0);
clear();
print_oltp();
time(%26amp;local_time);
ctime_r(%26amp;local_time,time_ch);
fprintf(acc_fd,"#### THESE ARE THE ACCOUNT informations...as on: %s",time_ch);
while(read(mdf_d,(char*)(%26amp;sb_acc),off... == off)
{
fprintf(acc_fd,"\n------------------...
fprintf(acc_fd,"\nAcc_no:%d\tPhone_n...
}
fprintf(acc_fd,"\n-------------------...
fprintf(acc_fd,"\n\n%26lt; FILE GENERATED BY OLTP CLIENT PROCESS WITH PID:%d %26gt;\n",getpid());
fprintf(acc_fd,"\n%26lt; Contact Shreenath Deshpande %26lt;mdshreenath@yahoo.com %26gt;\n");
printw("\n\t\t\tWRITTEN ./Accounts.txt\n");
return;
}
/*This function is to flag error*/
void print_error(int err)
{
printw("\n\t\t\t");
attron(A_BLINK | A_REVERSE);
switch(err)
{
case -55:
printw(" Balence UNDERFLOW......You can't WITHDRAW ! ! ");
break;
case -7:
printw(" AUTHENTIFICATION FAILED ! ! ");
break;
case -3:
printw(" OPEN ACCOUNT ERROR ! ! ");
break;
default:
printw(" OPEN ACCOUNT ERROR ! ! ");
break;
}
attroff(A_BLINK | A_REVERSE);
printw("\n\n\t\t\tpress[ENTER]");refr...
return;
}
/*This function is to just print welcome message*/
void print_oltp(void)
{
int cur_y,cur_x;
char started_time[30];
clear();
attron(A_DIM);
printw("-----------------------------...
attron(A_BOLD | A_REVERSE);
printw(" YOU ARE RUNNING OLTP--A CLIENT SERVER SIMULATION BY %26lt;mdshreenath@yahoo.com%26gt; \n");
attroff(A_BOLD | A_REVERSE);
printw("-----------------------------...
refresh();
getyx(stdscr,cur_y,cur_x);
move(MAX_Y-3,0);
printw("-----------------------------...
attron(A_BOLD | A_REVERSE);
printw(" PID:%d OLTP-CLIENT %s ",getpid(),TIME_STRING);
attroff(A_BOLD | A_REVERSE);
refresh();
printw("\n---------------------------...
refresh();
attroff(A_BOLD | A_DIM | A_REVERSE);
move(cur_y,cur_x);
return;
}
/*This function is to check for valid choice*/
int valid_choice(char c)
{
if( c=='c' || c=='e' || c=='v' || c=='d' || c=='w' || c=='x' || c=='a') return(1);
else return(0);
}
/*This function is to get an integer from charecters*/
int getint(void)
{
char string[10];
chtype c;
int i=-1,val,x,y,pos;
//attron(A_BOLD);
noecho();
while(1)
{
c=getch();
if(c == 10) break;
if(c == 27) return(-1);
if(isdigit(c) %26gt; 0)
{
echo();
printw("%c",c);
refresh();
i++;
string[i]=c;
noecho();
continue;
}
beep();
}
string[i+1]='\0';
val=atoi(string);
return(val);
}
/*Physical End*/
Project help.?
Why did you post twice?
survey software
/*
%26lt;"OLTP" a client-server simulation%26gt;
File Name:client_oltp.c
Discription:Compile %26amp; Run as CLIENT PROCESS.
*/
#include "oltp.h" /*This file contains all the header files needed for both Client and Server*/
/*Function prototypes*/
int chan_req(int,int);
OLTP_MSG_BUFF send_msg(int,int,OLTP_MSG_BUFF);
void print_mdf(void);
void print_error(int);
void print_oltp(void);
int valid_choice(char);
int getint(void);
/*Globle variables*/
int MAX_Y,MAX_X;
time_t LOCAL_TIME;
char TIME_STRING[30];
main()
{
int semd,msgd,i,j,acc_ph,acc_no,amount,pid,a...
chtype key,user_choice;
time_t local_time;
char time_string[30];
OLTP_MSG_BUFF master_req,req_msg,reply_msg;
initscr();
getmaxyx(stdscr,MAX_Y,MAX_X);
keypad(stdscr,TRUE);
raw();
echo();
attron(A_REVERSE);
printw("\n WELCOME TO OLTP--A CLIENT SERVER SIMULATION BY %26lt;mdshreenath@yahoo.com%26gt; \n\n");
sleep(1);
refresh();
attroff(A_REVERSE);
semd=semget(OLTP_SEMID,1,0);
if(semd %26lt;0)
{
printw("\n\t\t\tFailed semget().........Restart the Server ! !\n");
refresh();
getch();
endwin();
exit(1);
}
msgd=msgget(OLTP_MSGID,0);
if(msgd %26lt; 0)
{
printw("\n\t\t\tFailed msgget().........Restart the Server ! !\n");
semctl(semd,0,IPC_RMID,0);
refresh();
getch();
endwin();
exit(2);
}
req_msg.mtype=chan_req(msgd,semd);
time(%26amp;LOCAL_TIME);
ctime_r(%26amp;LOCAL_TIME,TIME_STRING);
TIME_STRING[24]='\0';
printw("\n\t\t\tStarted ON:");
refresh();
attron(A_DIM);
printw("%s\n\n",TIME_STRING);
refresh();
attroff(A_DIM);
printw("\n\t\t\tPRESS [ENTER] to continue...........");
refresh();
getch();
print_oltp();refresh();
req_msg.pid=pid=getpid();
while(1)
{
printw("\n\tPRESS\n");
printw("\t\t\tc:Create A New Account\n");
printw("\t\t\te:Edit Existing Account\n");
printw("\t\t\tv:View Account Information\n");
printw("\t\t\td:Deposite To Existing Account\n");
printw("\t\t\tw:Withdraw From Existing Account\n");
printw("\t\t\tx:Transactions OVER...Want to eXit ! !\n");
printw("\t\t\ta:Adminstration\n");
printw("\n\tCHOICE");
refresh();
attron(A_BLINK);
printw(":");
attroff(A_BLINK);
refresh();
noecho();
user_choice=getch();
if(user_choice == 27) user_choice='x';
else if(!valid_choice(user_choice))
{
attron(A_BLINK);
addch(user_choice);
attroff(A_BLINK);
refresh();
attron(A_DIM);
printw("--INVALID CHOICE");
refresh();
beep();
sleep(1);
attroff(A_DIM);
print_oltp();
continue;
}
echo();
IP_AGAIN: print_oltp();
refresh();
switch(user_choice)
{
case 'c':
attron(A_DIM);printw("\n\t\t\tYou Are about to CREAT new Account\n");
refresh();
attroff(A_DIM);
printw("\n\t\t\tAccount Payee Phone Number:");
refresh();
acc_ph=getint();
if(acc_ph%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tCONFIRM.. [Y/N] :");
refresh();
key=getch();
if(key == 'n' || key == 27) goto IP_AGAIN;
req_msg.acc_no=0;
req_msg.req_type=1;
req_msg.req_rep_info=acc_ph;
reply_msg=send_msg(msgd,1,req_msg)...
if(reply_msg.req_rep_info %26lt; 0)
{
print_error(reply_msg.req_rep_inf...
getch();
print_oltp();
continue;
}
attron(A_REVERSE);
printw("\n New Account Created !! #Acc_no:%d Having #Acc_ph:%d ",reply_msg.req_rep_info,acc_ph);
refresh();
attroff(A_REVERSE);
attron(A_DIM | A_BLINK);
printw("\n\npress [ENTER]");
refresh();
attroff(A_DIM | A_BLINK);
getch();
break;
case 'e':
attron(A_DIM);
printw("\n\t\t\tYou are about to EDIT an account\n");
refresh();
attroff(A_DIM);
printw("\n\t\t\tAccount Number:");
refresh();
acc_no=getint();
if(acc_no%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tNew Tel_No:");
acc_ph=getint();
if(acc_ph%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tCINFIRM... [Y/N]:",acc_no,acc_ph);
refresh();
key=getch();
if(key == 'n') goto IP_AGAIN;
req_msg.acc_no=acc_no;
req_msg.req_type=2;
req_msg.req_rep_info=acc_ph;
reply_msg=send_msg(msgd,2,req_msg)...
if(reply_msg.req_rep_info %26lt; 0)
{
print_error(reply_msg.req_rep_inf...
getch();
print_oltp();
continue;
}
attron(A_REVERSE);
printw("\n Account Edited !! #Acc_no:%d #New Acc_ph:%d ",acc_no,reply_msg.req_rep_info);
refresh();
attroff(A_REVERSE);
attron(A_DIM | A_BLINK);
printw("\n\npress [ENTER]");
refresh();
attroff(A_DIM | A_BLINK);
getch();
break;
case 'v':
attron(A_DIM);
printw("\n\t\t\tYou are about to VIEW an acount information\n");
attroff(A_DIM);
printw("\n\t\t\tAccount Number:");
refresh();
acc_no=getint();
if(acc_no%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tCONFIRM...[Y/N]:",...
refresh();
key=getch();
if(key == 'n' || key == 27) goto IP_AGAIN;
req_msg.acc_no=acc_no;
req_msg.req_type=3;
req_msg.req_rep_info=acc_no;
reply_msg=send_msg(msgd,3,req_msg)...
if(reply_msg.req_rep_info %26lt; 0)
{
print_error(reply_msg.req_rep_inf...
getch();
print_oltp();
continue;
}
attron(A_DIM);
printw("\n\t\t\t------------------...
printw("\n\t\t\tAccount No:%d",acc_no);
printw("\n\t\t\tTelephone No:%d",reply_msg.acc_no);
printw("\n\t\t\tCurrent Balence:%d",reply_msg.req_rep_info);
printw("\n\t\t\t------------------...
attron(A_BLINK);printw("\n\n\t\t\t... [ENTER]");
refresh();
attroff(A_DIM | A_BLINK);
getch();
break;
case 'd':
attron(A_DIM);
printw("\n\t\t\tYou are about to DEPOSITE\n");
attroff(A_DIM);
refresh();
printw("\n\t\t\tAccount Number:");
refresh();
acc_no=getint();
if(acc_no%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tDebit:");
refresh();
amount=getint();
if(amount%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tCONFIRM... [Y/N]:",amount,acc_no);
refresh();
key=getch();
if(key == 'n' || key == 27) goto IP_AGAIN;
req_msg.acc_no=acc_no;
req_msg.req_type=4;
req_msg.req_rep_info=amount;
reply_msg=send_msg(msgd,4,req_msg)...
if(reply_msg.req_rep_info %26lt; 0)
{
print_error(reply_msg.req_rep_inf...
getch();
print_oltp();
continue;
}
attron(A_REVERSE);
printw("\n Debited!! #Acc_no:%d Now Has #Ballence:%d ",acc_no,reply_msg.req_rep_info);
refresh();
attroff(A_REVERSE);
attron(A_DIM | A_BLINK);
printw("\n\npress [ENTER]");
refresh();
attroff(A_BLINK | A_DIM);
getch();
break;
case 'w':
attron(A_DIM);
printw("\n\t\t\tYou are about to WITHDRAW\n");
refresh();
attroff(A_DIM);
printw("\n\t\t\tAccount Number:");
refresh();
acc_no=getint();
if(acc_no%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tWithdraw:");
refresh();
amount=getint();
if(amount%26lt;=0)
{
print_oltp();
continue;/*goto infinite while again*/
}
printw("\n\t\t\tCONFIRM...[Y/N]:",...
refresh();
key=getch();
if(key == 'n' || key == 27) goto IP_AGAIN;
req_msg.acc_no=acc_no;
req_msg.req_type=5;
req_msg.req_rep_info=amount;
reply_msg=send_msg(msgd,5,req_msg)...
if(reply_msg.req_rep_info %26lt; 0)
{
print_error(reply_msg.req_rep_inf...
getch();
print_oltp();
continue;
}
attron(A_REVERSE);
printw(" Withdrawn !! #Acc_no:%d Now Has #Balence:%d ",acc_no,reply_msg.req_rep_info);
refresh();
attroff(A_REVERSE);
attron(A_DIM | A_BLINK);
printw("\n\npress [ENTER]");
refresh();
attroff(A_DIM | A_BLINK);
getch();
break;
case 'x':
attron(A_DIM);
printw("\n\t\t\tYOU ARE ABOUT TO EXIT\n\n");
refresh();
attroff(A_DIM);
printw("\n\t\t\tCONFIRM EXIT[Y/N]:");
refresh();
key=getch();
if(key == 'Y' || key == 'y')
{
req_msg.req_type=6;
req_msg.req_rep_info=req_msg.mtyp...
reply_msg=send_msg(msgd,6,req_msg...
if(reply_msg.req_rep_info == BYE)
{
printw("\n\t\t\tLogged OUT ON:");
refresh();
time(%26amp;local_time);
ctime_r(%26amp;local_time,time_string)...
attron(A_DIM);printw("%s\n",time...
refresh();
attroff(A_DIM);
}
else
{
printw("\n\t\t\tAbnormal EXIT ! !");
refresh();
}
sleep(1);
attron(A_BOLD);
printw("\n\t\t\tDO YOU WANT GENERATE ALL ACCOUNTS INFORMATION [Y/N]:");
refresh();
key=getch();
attroff(A_BOLD);
if(key == 'y') print_mdf();
attron(A_DIM);
printw("\nThanks FOR TRYING OLTP ! !");
printw("\nANY BUGS TO %26lt;");refresh();
attroff(A_DIM);
attron(A_BLINK);
printw("mdshreenath@yahoo.com");
refresh();
attroff(A_BLINK);
attron(A_DIM);
printw("%26gt;");
refresh();
attroff(A_DIM);
getch();
endwin();
exit(0);
}
print_oltp();
continue;
case 'a':
attron(A_BOLD);
printw("\n\t\t\t[YOU ARE ABOUT TO SHUTDOWN THE SERVER...]\n\n");
printw("\n\t\t\tWANT TO CONTINUE [Y/N]:");
attroff(A_BOLD);
refresh();
key=getch();
if(key != 'y')
{
print_oltp();
continue;
}
printw("\n\t\t\tADMIN KEY:");
refresh();
noecho();
refresh();
scanw("%d",%26amp;admin_key);
echo();
req_msg.req_type=7;
req_msg.req_rep_info=admin_key;
reply_msg=send_msg(msgd,7,req_msg)...
if(reply_msg.req_rep_info %26lt; 0)
{
print_error(reply_msg.req_rep_inf...
getch();
print_oltp();
continue;
}
clear();
print_oltp();
attron(A_BOLD);
printw("\n\t\t\tAS ADMINSTRATOR.....ON: ");
refresh();
attroff(A_BOLD);
time(%26amp;local_time);
ctime_r(%26amp;local_time,time_string);
attron(A_DIM);
printw("%s\n",time_string);refresh...
attroff(A_DIM);
sleep(1);
printw("\n\t\t\tDO YOU WANT GENERATE ALL ACCOUNTS INFORMATION..[Y/N]:");
refresh();
attroff(A_BOLD);
key=getch();
if(key == 'y') print_mdf();
attron(A_DIM);
printw("\nThanks FOR TRYING OLTP ! !");
printw("\nANY BUGS TO %26lt;");refresh();
attroff(A_DIM);
attron(A_BLINK);
printw("mdshreenath@yahoo.com");
refresh();
attroff(A_BLINK);
attron(A_DIM);
printw("%26gt;");
refresh();
attroff(A_DIM);
getch();
endwin();
exit(0);
default:
printw("\n\t\t\t");
attron(A_BOLD | A_BLINK | A_REVERSE);
printw("Wrong Choise");
refresh();
attroff(A_BOLD | A_BLINK | A_REVERSE);
getch();
print_oltp();
continue;
}/*End of Switch*/
print_oltp();
}/*infinite loop end*/
endwin();
}
/*This function is to send message to server through a channel number got using chan_req() function
This function returns reply message*/
OLTP_MSG_BUFF send_msg(int msgd,int msg_type,OLTP_MSG_BUFF req_msg)
{
int pid,nof_try=0;
char key;
OLTP_MSG_BUFF reply_msg;
printw("\n\t\t\tComunicating with the server...\n");
refresh();
while(msgsnd(msgd,(struct msgbuf*)(%26amp;req_msg),MSG_LEN,IPC_NOWAIT) %26lt; 0)
{
sleep(1);
nof_try++;
if(nof_try %26lt; 3) continue;
printw("\n\t\t\tServer NOT responding...TRY AGAIN [Y/N]:");
refresh();
key=getch();
if(key == 'N' || key == 'n')
{
printw("\n\t\t\tRestart the server.....\n");
refresh();
getch();
endwin();
exit(3);
}
}
pid=getpid();
nof_try=0;
while(msgrcv(msgd,(struct msgbuf*)(%26amp;reply_msg),MSG_LEN,pid,IPC_NOW... %26lt; 0)
{
sleep(1);
nof_try++;
if(nof_try %26lt; 3) continue;
printw("\n\t\t\tServer NOT responding...TRY AGAIN [Y/N]:");
refresh();
key=getch();
if(key == 'N' || key == 'n')
{
printw("\n\t\t\tRestart the server.....\n");
refresh();
getch();
endwin();
exit(4);
}
}
sleep(2);
printw("\n\t\t\t.....[DONE]\n");
refresh();
return(reply_msg);
}
/*This function is to requst the server process through MASTER CHANNEL for a uniq channel for
the future communication*/
int chan_req(int msgd,int semd)
{
int ret,key,nof_try=0;
OLTP_MSG_BUFF req_msg,reply_msg;
struct sembuf sops;
int pid;
pid=getpid();
req_msg.mtype=MASTER_CHAN;
req_msg.pid=getpid();
req_msg.acc_no=0;
req_msg.req_type=0;
req_msg.req_rep_info=getpid();
printw("\n\t\t\tRequesting Chanel for Communication...\n");
refresh();
sops.sem_num=0;
sops.sem_op=-1;
sops.sem_flg=0;
if(semop(semd,%26amp;sops,1) %26lt; 0)
{
printw("\n\t\t\tsemop failed ! !");
refresh();
getch();
endwin();
exit(1);
}
while(msgsnd(msgd,(struct msgbuf*)(%26amp;req_msg),MSG_LEN,IPC_NOWAIT) %26lt; 0)
{
sleep(1);
nof_try++;
if(nof_try %26lt; 3) continue;
printw("\n\t\t\tServer NOT responding...TRY AGAIN [Y/N]:");
refresh();
key=getch();
if(key == 'N' || key == 'n')
{
printw("\n\t\t\tRestart the server.....\n");
refresh();
sops.sem_op=1;
semop(semd,%26amp;sops,1);
getch();
endwin();
exit(2);
}
}
nof_try=0;
while(ret=msgrcv(msgd,(struct msgbuf*)(%26amp;reply_msg),MSG_LEN,pid,IPC_NOW... %26lt; 0)
{
sleep(1);
nof_try++;
if(nof_try %26lt; 3) continue;
printw("\n\t\t\tServer NOT responding...TRY AGAIN [Y/N]:");
refresh();
key=getch();
if(key == 'N' || key == 'n')
{
printw("\n\t\t\tRestart the server.....\n");
refresh();
sops.sem_op=1;
semop(semd,%26amp;sops,1);
getch();
endwin();
exit(2);
}
}
sops.sem_op=1;
semop(semd,%26amp;sops,1);
printw("\n\t\t\t.....GOT Chanel %d\n",reply_msg.req_rep_info);
refresh();
return(reply_msg.req_rep_info);
}
/*This function is to print the Master Data Base file in READABLE format*/
void print_mdf(void)
{
int off,mdf_d,i=1;
time_t local_time;
char time_ch[30];
FILE *acc_fd;
SB_ACC sb_acc;
mdf_d=open("./MDF.dbase",O_RDONLY);
acc_fd=fopen("./Accounts.txt","w");
if(acc_fd == NULL)
{
printw("\n\t\t\tERROR opening ./Accounts.txt\n");
return;
}
off=sizeof(struct SB_ACC);
lseek(mdf_d,0,0);
clear();
print_oltp();
time(%26amp;local_time);
ctime_r(%26amp;local_time,time_ch);
fprintf(acc_fd,"#### THESE ARE THE ACCOUNT informations...as on: %s",time_ch);
while(read(mdf_d,(char*)(%26amp;sb_acc),off... == off)
{
fprintf(acc_fd,"\n------------------...
fprintf(acc_fd,"\nAcc_no:%d\tPhone_n...
}
fprintf(acc_fd,"\n-------------------...
fprintf(acc_fd,"\n\n%26lt; FILE GENERATED BY OLTP CLIENT PROCESS WITH PID:%d %26gt;\n",getpid());
fprintf(acc_fd,"\n%26lt; Contact Shreenath Deshpande %26lt;mdshreenath@yahoo.com %26gt;\n");
printw("\n\t\t\tWRITTEN ./Accounts.txt\n");
return;
}
/*This function is to flag error*/
void print_error(int err)
{
printw("\n\t\t\t");
attron(A_BLINK | A_REVERSE);
switch(err)
{
case -55:
printw(" Balence UNDERFLOW......You can't WITHDRAW ! ! ");
break;
case -7:
printw(" AUTHENTIFICATION FAILED ! ! ");
break;
case -3:
printw(" OPEN ACCOUNT ERROR ! ! ");
break;
default:
printw(" OPEN ACCOUNT ERROR ! ! ");
break;
}
attroff(A_BLINK | A_REVERSE);
printw("\n\n\t\t\tpress[ENTER]");refr...
return;
}
/*This function is to just print welcome message*/
void print_oltp(void)
{
int cur_y,cur_x;
char started_time[30];
clear();
attron(A_DIM);
printw("-----------------------------...
attron(A_BOLD | A_REVERSE);
printw(" YOU ARE RUNNING OLTP--A CLIENT SERVER SIMULATION BY %26lt;mdshreenath@yahoo.com%26gt; \n");
attroff(A_BOLD | A_REVERSE);
printw("-----------------------------...
refresh();
getyx(stdscr,cur_y,cur_x);
move(MAX_Y-3,0);
printw("-----------------------------...
attron(A_BOLD | A_REVERSE);
printw(" PID:%d OLTP-CLIENT %s ",getpid(),TIME_STRING);
attroff(A_BOLD | A_REVERSE);
refresh();
printw("\n---------------------------...
refresh();
attroff(A_BOLD | A_DIM | A_REVERSE);
move(cur_y,cur_x);
return;
}
/*This function is to check for valid choice*/
int valid_choice(char c)
{
if( c=='c' || c=='e' || c=='v' || c=='d' || c=='w' || c=='x' || c=='a') return(1);
else return(0);
}
/*This function is to get an integer from charecters*/
int getint(void)
{
char string[10];
chtype c;
int i=-1,val,x,y,pos;
//attron(A_BOLD);
noecho();
while(1)
{
c=getch();
if(c == 10) break;
if(c == 27) return(-1);
if(isdigit(c) %26gt; 0)
{
echo();
printw("%c",c);
refresh();
i++;
string[i]=c;
noecho();
continue;
}
beep();
}
string[i+1]='\0';
val=atoi(string);
return(val);
}
/*Physical End*/
Project help.?
Why did you post twice?
survey software
Subscribe to:
Posts (Atom)