|
The recursion used in the final_array function not working.
#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;
}
modified 16-Dec-17 13:25pm.
|
|
|
|
|
what does "not working" mean?
[edit]
Looking back this seems to be a continuation of your previous questions, but much the same issue. I would strongly suggest you get hold of a good book on C programming and spend a lot of time studying the principles, and getting familiar with structures, arrays, functions etc.
[/edit]
|
|
|
|
|
can you name some book's, or you can tell me what my mistake is and how can i correct it. 
|
|
|
|
|
There are plenty of books around. Try a google search or go to your local bookshop.
|
|
|
|
|
I started with a book by Scott Meyers called "Beginning C" or something like that. I can't seem to find it now so it may be out of print.
|
|
|
|
|
in the below code it prints for arr[0] and not after it. please tell to correct.
<pre>
#include <stdio.h>
int i, j;
int arr[100][100];
void array(int arr[i][j], int size[i+1])
{
for(j=0; j<size[i+1]; j++)
{
scanf("%d", &arr[i][j]);
printf("arr[%d][%d]\n", i, j);
}
}
int main()
{
int num,size[100];
printf("Enter the number of arrays: \t");
scanf("%d", &num);
size[0] = 0;
for(i=0; i<num; i++)
{
printf("\nEnter the size of the array: \t");
scanf("%d", &size[i+1]);
printf("\nEnter the array: \n");
array(arr, size);
}
for(i=0; i<num; i++)
{
for(j=0; j<size[i+1]; j++)
{
printf("\n%d", arr[i][j]);
}
}
return 0;
}
|
|
|
|
|
I cannot figure out what you are trying to do but most of what you have makes no sense at all. Statements such as:
void array(int arr[i][j], int size[i+1])
scanf("%d", &arr[i][j]);
printf("arr[%d][%d]\n", i, j);
|
|
|
|
|
the user will input n number of arrays of different array sizes, and then the program will print every array that user has entered.
I want to create a program that will merge n number of arrays.
|
|
|
|
|
To create the arrays you need to get the size of each dimension and then create the array dynamically. You cannot pre-allocate them if you do not have their size. Once you have all the requested arrays then you need to create another one that will contain the results of your merge.
|
|
|
|
|
if you run the code it will take the size of array first and then fill in the respective elements in according to the size entered.
But i am not able to print it on the screen.
Please run it and tell me what's wrong.
|
|
|
|
|
Like I already told you, much of that code makes no sense, so there is no point in me trying to run it. You need to sort out the logic first.
|
|
|
|
|
|
#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?
|
|
|
|
|