|
|
#include <stdio.h>
void array(int arr[], int i, int size)
{
for (int j = 0; j<size; j++)
{
printf("\nEnter arr[%d][%d]: \t",i, j);
scanf("%d", &arr[j]);
}
}
int main()
{
int num, size[100];
int i, j;
int arr[100][100];
printf("Enter the number of arrays: \t");
scanf("%d", &num);
num = num < 100 ? num: 100;
for (i = 0; i<num; i++)
{
printf("\nEnter the size of the array: \t");
scanf("%d", &size[i]);
printf("\nEnter the array: ");
size[i] = size[i] < 100 ? size[i] : 100;
array(&arr[i][0], i, size[i]);
}
for (i = 0; i<num; i++)
{
printf("\n");
for (j = 0; j<size[i]; j++)
{
printf("%d\t", arr[i][j]);
}
}
printf("\nPress Enter key to exit.\n");
getchar();
return 0;
}
modified 11-Dec-17 15:28pm.
|
|
|
|
|
so the problem was = array(arr, size, i) instead of array(&arr[i][0], size, i).
Thank you so much
|
|
|
|
|
in the code below i have tried using recursion for printing output, but it's not working can you tell me what's wrong.
<pre>#include <stdio.h>
int final_array(int arr[], int size, int k, int i);
void array(int arr[], int i, int size);
int main()
{
int num, size[100];
int i, j, k=0;
int arr[100][100];
printf("Enter the number of arrays: \t");
scanf("%d", &num);
num = num < 100 ? num: 100;
for (i = 0; i<num; i++)
{
printf("\nEnter the size of the array: \t");
scanf("%d", &size[i]);
printf("\nEnter the array: ");
size[i] = size[i] < 100 ? size[i] : 100;
array(&arr[i][0], i, size[i]);
}
for(i=0; i<num; i++)
{
final_array(&arr[i][0], size[i], k, i);
printf("\n");
}
printf("\nPress Enter key to exit.\n");
getchar();
return 0;
}
void array(int arr[], int i, int size)
{
int j;
for (j = 0; j<size; j++)
{
printf("\nEnter arr[%d][%d]: \t",i, j);
scanf("%d", &arr[j]);
}
}
int final_array(int arr[], int size, int k, int i)
{
if(k<=size)
{
printf("%d", arr[k]);
final_array(&arr[i][0], size[i], k++, i);
}
else
return 0;
}
|
|
|
|
|
Hello,
I am trying to solve my OpenGL pyramid project. If anyone can please help me with a code as soon as possible.
I have to do when I build the code it will come black window After that perform the following task:
01. F1+r = 60' rotation(static)
02. F2+r =45' rotation(continuous x-axis)
03. CTRL+w = White
04. B = Black
Thanks for your concern and help.
#include <stdlib.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
float red=1.0f, blue=1.0f, white=1.0f;
float angle = 0.0f;
void changeSize(int w, int h) {
if (h == 0)
h = 1;
float ratio = w * 1.0 / h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(45.0f, ratio, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
}
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt( 0.0f, 0.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
glRotatef(angle, 1.0f, 1.0f, 0.0f);
glColor3f(red,white,blue);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f, 1.0f);
glEnd();
angle+=0.1f;
glutSwapBuffers();
}
void processNormalKeys(unsigned char key, int x, int y) {
if (key == 27)
exit(0);
}
void processSpecialKeys(int key, int x, int y) {
switch(key) {
if(key=='1')
{
angle+=10;
}
if(key=='0')
{
angle+=1;
}
case GLUT_KEY_F1 :
red = 1.0;
white = 0.0;
blue = 0.0;
; break;
case GLUT_KEY_F2 :
red = 0.0;
white = 1.0;
blue = 0.0; break;
case GLUT_KEY_F3 :
red = 0.0;
white = 0.0;
blue = 1.0; break;
}
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(640,480);
glutCreateWindow("Lighthouse3D- GLUT Tutorial");
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutIdleFunc(renderScene);
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(processSpecialKeys);
glutMainLoop();
return 1;
}
|
|
|
|
|
CPU Speed and RAM Manufacturer.
|
|
|
|
|
Do not try to do that, natively.
Instead, consider using the platform specific APIs, such as the Linux APIs for C or the Win32 API on Windows. The benefit is that you will be able to get the information, such as the information about hardware (I am not sure, whether you will be able to dig that much information or not).
Start from somewhere like this,
How to get current CPU and RAM usage in C++? - Stack Overflow
sysinfo(2) - Linux manual page
You would then need to go on other platform APIs such as the Win32, and find out what is offered there. Such as, GetSystemInfo function (Windows) will provide the system info for CPU.
One thing is for sure: What works on Linux with C, is not going to work on Windows and vice versa. Also, none of this guarantees to provide CPU make, or RAM manufacturer name. In most cases, you will have to pull down a complete stream of data, and then parse it to extract the interested portion; such as in this post, How to check processor and cpu details on Linux | Linux.com | The source for Linux information
$ cat /proc/cpuinfo | grep vendor | uniq
vendor_id : GenuineIntel
$ cat /proc/cpuinfo | grep 'model name' | uniq
model name : Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz
$ lscpu
Architecture: x86_64
Which shows, that you will have to extract and then parse the data to show the interested part; otherwise, that doesn't quite work that way.
Good luck Googling.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I'm using vista style of cfiledialog and don't want the open button's default drop down, I just want the open button. How to disable the open button's drop down??
|
|
|
|
|
You would most likely need to derive your own class with modified behaviour.
|
|
|
|
|
Using templates? i'm using vista style
|
|
|
|
|
IMO, changing the behaviour of a common control (such as CFileDialog) is a bad idea. Your users have grown to expect that common controls behave in a certain way, and changing that only makes your program less intuitive.
Perhaps you should think upon why you want to change this behaviour.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
The problem is maintaining consistency, I'm using an IFileDialog to open files on some computers, it all works as expected in win10, but on others win7 ultimate, the Open button has an arrow with a dropdown menu that adds a second option, "show previous versions".
|
|
|
|
|
Hello everybody
i have a mfc application project in Visual studio 2010. it is a GUI infact.
i want to get communication with a mini circuit signal generator device. the device has a dll file named "mcl_gen64.dll
i want to use functions of that dll in my code but i dont have any idea how to do this
any idea please?
|
|
|
|
|
What is it that you don't understand? How to code the function calls, or how to include the library in your project? What does the documentation say that came with the library?
|
|
|
|
|
i had tried this:
#import "mcl_gen.dll" in my .h file
and i have written this piece of code in my .cpp file:
"
typedef int (*ConnectByAddressfuncPtr)(short Addr);
HINSTANCE LoadME;
LoadME = LoadLibrary("mcl_gen.dll");
// Check to see if the library was loaded successfully
if (LoadME != 0)
printf("LoadMe library loaded!\n");
else
printf("LoadMe library failed to load!\n");
ConnectByAddressfuncPtr LibMainConnectByAddress;
LibMainConnectByAddress = (ConnectByAddressfuncPtr)GetProcAddress(LoadME,"ConnectByAddress");
int x = LibMainConnectByAddress(0x01);
"
"ConnectByAddress" is a function in .dll file
when i run the code although the dll file is being loaded but i get this error:
Unhandled exception at 0x770115ee in fdll.exe: 0xC0000005: Access violation.
|
|
|
|
|
Well that just indicates that you have a bad address somewhere in the code. You need to use your debugger to find out where it occurs and why.
|
|
|
|
|
you mean that i have loaded .dll file correctly and the error is because of somewhat like syntax error?
but i have exactly copied the name of function in dll.
i dont know why this error occurs
|
|
|
|
|
I have no idea why the error occurred, beyond saying that is is caused by a bad address reference somewhere. And the only way to find out where it occurred is by using the debugger. Are you certain that the parameter 0x01 that you send to the ConnectByAddress function is valid? Check the documentation to see what that function is supposed to do, and what it is supposed to return.
|
|
|
|
|
To use functions from a DLL you have two choices: Early and late binding.
Early binding:
Link your application with the DLL by using the #import directive in one file (usually a source file using functions from the DLL) specifying the file name (usually without extension or with .lib), or add the .lib file to your project settings (Linker - Input).
Include the header file and call the functions defined in that file.
Late binding:
This is only necessary if the DLL might not be present when your application is executed or you do not have a .lib file. Then use LoadLibrary and GetProcAddress like in your above example. But check both return values to be not NULL . Have a look at the header file (if present), to know how to define the function prototypes. Example:
typedef int (__stdcall *ConnectByAddressfuncPtr)(short Addr);
ConnectByAddressfuncPtr LibMainConnectByAddress = NULL;
HMODULE hLib = LoadLibrary(_T("mcl_gen.dll"));
if (hLib)
LibMainConnectByAddress = (ConnectByAddressfuncPtr)GetProcAddress(hLib,"ConnectByAddress");
if (LibMainConnectByAddress)
LibMainConnectByAddress(0x01); Note that I have initialised the function pointer with NULL and checked it before calling the function. Note also the __stdcall in the prototype declaration. It defines the calling convention used by the DLL. You have to check which is used (by inspecting the header file or asking the provider). __stdcall is common but it might be also __cdecl .
|
|
|
|
|
Hi. thank you for your answer. i dont have any .lib file
i tried your code but "LibMainConnectByAddress" still remains NULL. so the code skips
LibMainConnectByAddress(0x01);
do you know why?
thank you again
|
|
|
|
|
All I can suggest is to check if the DLL exports the function "ConnectByAddress" (e.g. using the Dependency Walker (depends.exe) Home Page[^] or executing dumpbin /exports path_to_dll on the command line; dumpbin is in the VC/bin folder) and trying it with different calling conventions like __cdecl .
I would use the Dependency Walker because it shows also the calling convention for the exported functions.
|
|
|
|
|
Member 13471493 wrote: "LibMainConnectByAddress" still remains NULL. You omitted to mention that in your reply to me. If that function pointer is null then it will cause the error you have seen. You need to check the function name that you are trying to get the address for, does it actually exist in the dll?
|
|
|
|
|
Yes it Does. i tried others functions that exist in dll too. but i got the same error. i am sure about syntax and existence of these functions in the dll.
|
|
|
|
|
But are you sure that the value you are sending to the function is correct?
|
|
|
|
|
Have you used the Dependency Walker or dumpbin meanwhile?
The exported names may be mangled (see Name mangling - Wikipedia[^] ). Then you have to pass the mangled name to GetProcAddress .
|
|
|
|
|