|
Mircea Neacsu wrote: struct tm *systime = localtime(&now); I've never understood declaring a variable as struct* .
struct is a keyword used to define a UDF. It's not a type in itself.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
tm is a regular structure and localtime (as well as gmtime) return a pointer to an internal buffer.
Quoting from cplusplus.com:[^]
Quote: A pointer to a tm structure with its members filled with the values that correspond to the local time representation of timer.
The returned value points to an internal object whose validity or value may be altered by any subsequent call to gmtime or localtime.
Now that I look again at the code I see that I missed the call to time(&now) . Oops!
Mircea
|
|
|
|
|
It is simply a pointer to a structure that gets filled in by the system call. What is wrong with that?
|
|
|
|
|
It bothers me because it would be akin to saying:
class *Foo = new Foo(); Is that legal C++?
EDIT:
Oh wait, I didn't notice that there is a struct name followed by a variable name. I see now.
The difficult we do right away...
...the impossible takes slightly longer.
modified 31-Oct-20 16:37pm.
|
|
|
|
|
Richard Andrew x64 wrote: Is that legal C++? Yes, and necessary. Pointers must actually point to something, or they are just empty space.
|
|
|
|
|
You misunderstood what I was demonstrating. I was demonstrating declaring a variable of type "class*". Is it possible to declare a variable of type "class"? Is there such a type?
I don't think that's legal in C++. I haven't tried it though.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard Andrew x64 wrote: Is it possible to declare a variable of type "class"? No, because class is an abstract concept, not a type in the same sense that int is. The actual type will be the name used in the class definition. For example consider the following:
class Foo
{
public:
Foo() { std::cout << "Constructing a Foo object" << std::endl; }
};
int main(int argc, char** argv)
{
Foo aFoo;
Foo* pFoo = new Foo();
}
A new object aFoo is created and stored on the local stack. A second new object is instantiated on the heap and its address passed back to be stored in the pointer pFoo . The type of both objects is Foo not class .
Does that make sense?
modified 2-Nov-20 6:39am.
|
|
|
|
|
You can use the difftime() function to subtract two time_t values. If you have the time in a struct tm, you can convert it to time_t using the mktime() function. The strftime() function formats a struct tm to text format.
These APIs are all available in C90, but some options were introduced as of C99.
difftime() should incorporate leap-seconds for past dates, but I don't know if actual implementations do so.
Note that issues such as daylight-saving time, time zones, etc. are left to the programmer. Ignoring these is a common way for programmers to shoot themselves in the foot.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Hi all,
PLease help me for Searching and displaying a record in Array of Structure in c. I think i am meesing up with pointer and array index. PLease help
struct employee{
int emp_id;
char emp_name[30];
}emp[MAX];
void findAllDetails(int *e){
printf("\n Employee Details...\n");
printf("\n Emp No : %d", emp.emp_id);
printf("\n Emp Name : %s", emp.emp_name);
}
void PrintAllDetails(int &K){
for(i=0;i<MAX;i++){
if(K==&emp[i].emp_id)
break;
if(i<MAX)
{
findAllDetails(&emp[i]);
}
}
modified 29-Oct-20 22:51pm.
|
|
|
|
|
I would have written something similar to
#include <stdio.h>
#define EMPLOYEE_ARRAY_SIZE 10
#define NAME_MAX_LENGTH 30
#define NOT_FOUND -1
struct employee
{
int id;
char name[NAME_MAX_LENGTH];
};
int find_employee_by_id( const struct employee emp_array[], int emp_array_size, int id);
void print_employee( const struct employee * pemp );
int main()
{
struct employee emp_array[EMPLOYEE_ARRAY_SIZE] =
{
{ 1, "foo"}, {2, "boo"}, {3, "goo"}, };
int id = 2;
int index = find_employee_by_id( emp_array, EMPLOYEE_ARRAY_SIZE, id );
if ( index != NOT_FOUND )
{
printf("found emplyee details:\n");
print_employee( & emp_array[index] );
}
else
{
printf("employee with id = %d not found\n", id);
}
return 0;
}
int find_employee_by_id( const struct employee emp_array[], int emp_array_size, int id)
{
int index;
for (index = 0; index < emp_array_size; ++ index)
if ( emp_array[index].id == id)
return index;
return -1;
}
void print_employee( const struct employee * pemp )
{
printf("id = %d\n", pemp->id);
printf("name = %s\n", pemp->name);
}
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
I need my existing MDI application in MFC to be transformed with the below requirement.
Every window should look like a completely separate instance of the application – with its own button in the Windows Taskbar. However the windows should be still part of the single application.
If there are multiple monitors used, each window of my application can be viewed in the various montitors
Please give your suggestions how to convert
|
|
|
|
|
Make a client-server architecture. Each window (running as a separate program) is nothing but a display facilty, just like a web browser, with no application logic, no (application) data structures. Everything is done in your server, i.e. your old application deprived of display facilities.
The architecture would be like a database accessed across the web.
|
|
|
|
|
My Application takes very less data (configuration) from text files, rest are all calculations done every second for around 20000 tags or values. If I do it using TCP/IP Sockets that my application may be overloaded for each window. Is there any other option in MFC?
|
|
|
|
|
I do not work with MFC myself, so this is just results from a little documentation searching.
TCP/IP is certainly not a lightweight mechanism, but pipes are. In the original Unix design (from the early 1970s), the processes in either end had to have a common ancestor, creating the pipe, but later we got named pipes, CreateNamedPipeA function[^] so that arbitrary processes can communicate across them. This has far less overhead than an TCP/IP socket.
You also have the CSharedFile Class[^] and CMemFile Class[^], making RAM look like a file; you use file operations to access RAM.
There is the opposite function: To make a disk file look like RAM, a "memory mapped file". In the old days, you couldn't do that from C#, you had to use C/C++. Now I find only the dotNet version (at MemoryMappedFile Class[^]), but of course it is still is provided in C/C++; I just can't find it (I would think that CSharedFile and CMemFile are thin layers on top of that mechanism.) You may be more clever than I am in finding the C++ equivalent. It is there, somewhere...
A memory mapped file does not require an underlaying disk file; you use the same facility for creating a data segment accessible from multiple processes. Using a shared segment, a.k.a. a memory mapped file, is certainly the fastest way to exchange data between processes, comparable to threads accessing shared data within a process: The memory management system handles it. The greatest advantage, compared to a file/pipe solution: You don't have to serialize (or marshal, or whatever your call it) your data structures, but can access them "as is". For pointer based structures, all processes accessing the shared data segment obviously must map it to the same logical address. Equally obvious: You are responsible for all synchronization yourself, which must be done with semaphores (or whatever higher level mechanism) at system level, available to all processes. It will be somewhat more costly than a single-process implementation, but it doesn't have to be much, especially if there a single process (the server) updating the data, other processes only reading/displaying them.
|
|
|
|
|
|
Still, IPC may be one way to solve is problem.
|
|
|
|
|
I cannot disagree...
however, it depends.
|
|
|
|
|
Thanks that you got my requirement correctly. All I need... is a single application in which all the opened documents looks like in MS Office (Word, Excel).
There is already an option in MFC to create application type as "multiple top level documents" which meets my requirements.
Can you please suggest how to convert my existing MDI application from "Multiple Document Interface" type to "multiple top level documents" type.
Please help.
|
|
|
|
|
|
There is an option in MFC to create application type as "multiple top level documents" which meets my requirements.
Can you please suggest how to convert my application from "Multiple Document Interface" type to "multiple top level documents" type.
Please advise.
|
|
|
|
|
manoharbalu wrote: Can you please suggest how to convert my application from "Multiple Document Interface" type to "multiple top level documents" type. I would suggest creating a dummy program of each type and compare the boilerplate code.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I am a beginner in programming and I am trying to solve this problem using queues. I can't seem to come with an idea to solve it.
Can you help please, it is a problem just to learn about how to approach queue problems.
|
|
|
|
|
The very minimum for you to do is to describe the problem, more than "this problem". Then you should go on to show what you have done, and where you are stuck.
You can't expect people to promise to solve your problems when you haven't even told what the problem is!
|
|
|
|
|
|
fecomevi wrote: Can you help please, it is a problem just to learn about how to approach queue problems. A queue is a FIFO data structure. What exactly are you doing with it? Are you using std::queue , or a home-grown version? What code do you have in place so far?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|