|
A3
int main(int argc, char* argv[]){
char dateStr [9];
char timeStr [9];
_strdate_s( dateStr,9);
_strtime_s( timeStr,9);
//do what you want with variables;
printf("Time is %s date is %s",timeStr,dateStr);
system("pause");
return 0;
}
Cannot advise in other questions..
Sorry!
|
|
|
|
|
Sorry - didn`t read your post carefly - my answer won`t help you...
|
|
|
|
|
Q1 - why did you post this twice ?
Q2 - If someone does this for you, how do you hope to be able to do your next piece of homework ?
Q3 - These questions are really easy, did you sleep in class, lose your text and forget to use google, or would you just be better off doing a different course ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I recommend you make your homework yourself.
|
|
|
|
|
1) We are writing a DOS based application in which we have to display the system date and time. Write down the code for doing so.
2) As we know that in a windows application whenever a key is pressed, a message is sent to the active window. We are developing a DOS based application and want to detect whenever a key is pressed from keyboard. How can we do so?
3)We want to store the information about a student. This information includes student’s name, address and roll number. What data type (either built in or user defined) should be used to store all this information in a single variable.
Also we want to store the marks obtained of a student. The marks can be of type integer, character or float. We have to store the student’s marks in a variable of a particular data type. What data type (either built in or user defined) should be used to handle such a wide range of values.
Dure-shehwar
|
|
|
|
|
Dure-Shehwar wrote: 1) We are writing a DOS based application in which we have to display the system date and time. Write down the code for doing so.
Use the time-related APIs.
Dure-Shehwar wrote: 2) As we know that in a windows application whenever a key is pressed, a message is sent to the active window. We are developing a DOS based application and want to detect whenever a key is pressed from keyboard. How can we do so?
One such way is with getchar() .
Good luck with your homework. Next time, either go to class or don't sleep when you do go. Read #9 here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Good luck with your homework
Nice
|
|
|
|
|
(1)GetSystemTime();
----------------
(2)David Crow answer
---------------
(3)Single variable?
|
|
|
|
|
WhiteSky wrote: GetSystemTime();
In DOS? Are you smoking the good stuff today?
led mike
|
|
|
|
|
I think he needs only to get time/date .
But why smoking
|
|
|
|
|
You've already got a lot of excellent answers.
I made it to "Write down the code for doing so." and stopped. Without a "PLEASE"?
BTW:
Everyone knows to do stuff in DOS you write a Windows program to do the task and call
it from the DOS program.
Enjoy!
|
|
|
|
|
Mark Salsbery wrote: I made it to "Write down the code for doing so." and stopped. Without a "PLEASE"?
He's copying his homework into CP. His teacher didn't say please, so neither did he
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
Dear everyone;
I have got a pure C++/ algorithmic question that i would appreciate your input towards.
I have a number of files (lets say 100 files) of similar input formats. To reduce the complexity of the problem I will give you a simplied example:
File 1: File 2: File 3:
A A B
B E A
C D D
D D F
E F E
I want to write a program which produces a tree from the files, in which the first node is the node from the first line (from above) with the highest number of occurences ('A' in this case). Consequently File 3 will be ignored.
The resulting tree will be something like
A (100%)
B (50%) E (50%)
C (50%) D (50%)
D (100%)
E (50%) E (50%)
SO basically the program should go through the files and construct a tree with a % value of each node. every time branching occurs the % will be divided depending on the number of children.
My question is, is there any specific algorithm / similar algorithms which i can use to overcome this problem ? and What's the best way to visualise the tree?
Your help is very much appreciated
Best Regards
llp00na
|
|
|
|
|
llp00na wrote: File 1: File 2: File 3:
A A B
B E A
C D D
D D F
E F E
You've not used alignment correctly (use the <pre> tags) so I'm unclear as to what the three files look like.
llp00na wrote: Consequently File 3 will be ignored.
Why?
llp00na wrote: The resulting tree will be something like
A (100%)
B (50%) E (50%)
C (50%) D (50%)
D (100%)
E (50%) E (50%)
Does this tree branch to the right, or does it branch downward? Again, alignment would make the difference here.
llp00na wrote: SO basically the program should go through the files and construct a tree with a % value of each node. every time branching occurs the % will be divided depending on the number of children.
What exactly does this mean? Use percentages other than 100 and 50 so that we can see how the files relate to the nodes.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
My problem -
I wrote an application that reads com port in a loop and stores received data in log file.
Everything was O.K. , but then i needed to add *.ini file to my app. I`ve constructed a small inifile class to get port settings, etc. from *.ini. Everything works just fine, but, one thing. For example - to define BaudRate i used my inifile class to return int value fo parameter e.g 9600 not CBR_9600.
As i came to StopBits section I realized that ONESTOPBIT is defined as 0 which, which means - I have to store StopBits as its int value - 0. The thing that bothers me is that it`s hard for user to understand - why the hell section StopBits has to be 0, not ONESTOPBIT or 1. Is there any way I could store this value in my config file as string "ONESTOPBIT" and then pass it to DCB as its defined value, without using switch or any other unneeded stuf in my inifile class. Hope somebody will be able to understand what I wrote here..... Please help - I`m stuck on this for whole day already...
|
|
|
|
|
what's wrong with reading in a string, comparing it to a value (or looking it up in a table of
values), and passing on the appropriate integer?
TCHAR szValue[128];
(...read string into szValue from ini/configuration file...)
DWORD dwStopBits;
if (0 == _tcscmp(szValue, _T("ONESTOPBIT"))
dwStopBits = 0;
else
dwStopBits = 1;
>>...without using switch or any other unneeded stuf...
If it makes it easier for the user, is it really unneeded? Sometimes a little code is required
IMO
Mark
|
|
|
|
|
As far as the setting is for StopBits - no problem, but think about what happens, when you want to set baudrate(there are more options available) or, for example pass some GENERIC_READ to CreateFile() e.g. Could this be that there is no way to store DWORD defined variable in *.ini file, and then pass it back to app??
|
|
|
|
|
First
I agree with Zac that XML is a better way to go.
If you must use an ini file there's no problem converting text to a DWORD...
Take a look at atol() and similar functions which convert text to numeric values.
As always, you'll want to check the validity of anything entered by a user
Mark
|
|
|
|
|
Instead of using an INI file, you might try using an XML file. It will be easier to group settings (so if you ever decide to store multiple settings in the same file -- say, for multiple com ports), and it is easier to incorporate type checking.
The value of ONESTOPBIT is 0 because there are 3 values for stop bits (1, 1.5, and 2). Since it isn't good to use a float/double for such, an integer is used (basically as an enum). If you want to allow users to edit the configuration files manually, just use strings and assume default values if the strings are invalid.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanx for reply - ill stick to using switch() or that kind of stuff in this case, but the method for storing ONESTOPBIT e.g as string and then read back its defined DWORD value still bothers me - I want to figure it out...
P.S.
Yes - I know about xml files, but this isn`t the case I would need it.
|
|
|
|
|
Makakuin wrote: Thanx for reply - ill stick to using switch() or that kind of stuff in this case, but the method for storing ONESTOPBIT e.g as string and then read back its defined DWORD value still bothers me - I want to figure it out
Are you saying you want to store it like this:
; Valid values are ONESTOPBIT, ONE_5STOPBIT, TWOSTOPBIT
StopBits=ONESTOPBIT
or like this:
; Value values are 1, 1.5, 2
StopBits=1
In the first case, just use string comparisons. In the second, you have a couple options as well: Read them in as floats and use conditionals to set them to the proper setting (a bit risky since precision can be an issue), or force the values to be multiples of 10x so the file would look like this instead:
; Value values are 10, 15, 20
StopBits=10
Then simply use a switch statement to convert those integers to the proper defined values for stop bits.
Your best bet for making it easily readable is still to use XML and create a schema to validate it against so that you can let the parser determine if you have valid values before you even look at the data.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
What I mean is:
For now I use:
//////////////////////////////
DCB dcb;
dcb.BaudRate = inifile.getInt("Baudrate"); //Accepts int
dcb.StopBits = inifile.getInt("StopBits");//Accepts int
//////////////////////////////
and so on...
inifile is my created class where getInt(char* paramname) is returning value of type 'int', which is acceptable to DCB class. As you know originaly it would be done like this:
/////////////////////////////
dcb.BaudRate = CBR_9600; //Accepts DWORD
dcb.StopBits = ONESTOPBIT; //Accepts DWORD
/////////////////////////////
where CBR_9600 and ONESTOPBIT are defined by c++ like 9600 and 0.
What I want to do is store those settings in config file (doesn`t matter ini or xml) as strings CBR_9600 and ONESTOPBIT and then read them.
This won`t work:
//////////////////////////////
dcb.BaudRate = inifile.getTxtVal("BaudRate");
//////////////////////////////
because getTxtVal() returns char[] (wich is not acceptable for DCB) variable containing CBR_9600.
May be it is now easyer to understand what i was trying to say....
But maybe I`m a lOl.
-- modified at 15:30 Thursday 12th October, 2006
|
|
|
|
|
Makakuin wrote: strings CBR_9600 and ONESTOPBIT
You can store them as strings, but you will have to do a string comparison in your code to convert them. ONESTOPBIT, CBR_9600, etc are usually either #define's or enums (can't remember off the top of my head, but it doesn't matter). If you get a string "ONESTOPBIT" in, you can't convert that to ONESTOPBIT (the constant) by just casting it; you have to tell it what you want it to be:
string sBaud = inifile.getTxtVal("BaudRate");
unsigned long baud = CBR_38400;
if (sBaud == "CBR_9600")
{
baud = CBR_9600;
}
else if (sBaud == 14400)
{
baud = CBR_14400;
}
...
dcb.BaudRate = baud;
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanx that was exactly what I wanted to know .
It`s a pity that there`s no way to use the returned string directly..
O.K. ill start to write the missing piece of code for my inifile class..
Thanks again!
Raivo Jirgensons
|
|
|
|