|
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
|
|
|
|
|
Is Abort Retry Ignore something to be implemented by Structured Exception Handlers google the two didn't seem like there is a connection
thanks
|
|
|
|
|
Well, I understand that "Brevity is the soul of wit.", but could you explain more specific what your problem is and the relation between "Abort Retry Ignore" and "Structured Exception Handlers" in this context?
|
|
|
|
|
There is no such thing as "Abort Retry Ignore" per se. They are merely potential replies to dialog/message boxes. What you do with each individual reply is entirely your choice.
|
|
|
|
|
There is no such thing as "Abort Retry Ignore" per se. The closest I can think of is one old machine I knew: A fault handler would receive the address of the faulting instruction and a pointer to the register block, with the program pointer set to the following instruction. So, default handler return was "Ignore". Copying the faulting address to the program counter before handler return would be "Retry" at instruction level. Copying the return address from the stack frame pointed to by SP would be "Abort" at the function call level. (The handler could traverse the stack to find an outer return address.)
This is "Abort Retry Ignore" at instuction level, not directly appliccable to SEH. Actually, I am not certain that compiler writers made much use of the mechanisms at all. This machine offered several other features intended to make life easier for the software, but the software guys said "Nah. We'll do it our own way".
|
|
|
|
|
So the pcontext structure (which is in the pxeception pointer parameter structure) which has the registers is what I can manipulate the os windows will use those to continue processing
on abend the eip points to he instruction after the abend backing up the eip would allow me to do a retry
thanks
|
|
|
|
|
This machine I mentioned was not a Windows machine, and not an Intel architecture. At instruction / register level, you cannot expect any one-to-one mapping of concepts.
Also, you cannot map software concepts, like an exception handler, directly onto the interrupt system of every different CPU architecture. Often, a compiler will add a lot of its own to the basic hardware mechanisms. E.g. most exception mechanisms identify the proper handler by the static nesting, but that is within one function. Languages with nested function definitions, "Pascal style", may define handler identification and/or propagation by the overall nesting structure, requiring the static link in the stack frame to be followed. Unless you know every tiny detail of how the compiler generates code, and the runtime handler library (which may be written in assembly code and diverge from the compiler's code generation style), manipulating return addresses and other register contents is likely to mess up your system completely. (And don't forget that hardware fault handlers may be running in privileged mode, allowing you to really mess up your system!)
So, if you work at software SEH level, stick to that level, and don't mess with registers and return addresses.
(My comment was meant as an aside to the "Abort, Retry or Ignore?" not existing per se - just to illustrate that you can get close. I didn't intend it as a viable solution to your problem!)
|
|
|
|
|
in the SEH I can set the EIP from the pcontext structure to the abended instruction to do a retry right ?
|
|
|
|
|
I have no idea what that means. Please provide some proper context to your questions.
|
|
|
|