|
Hi.
I created a class which is derived from CTabView. In OnCretae() function it created a window with a tab control on window. Later i created few views by calling AddView(). I created 5 view.
Now, when i click on the arrow buttons on the tab control below, my control is not switching the tabs.
May i know which function should i call to switch the tabs on my window?
|
|
|
|
|
|
Hi.
In my MFC application, i created a class which is derived from CTabView and created few tabs(views) using AddView(). Now i want to change the color of the tab views. May i know how to change the background color of those views?
Thanks in Advance.
|
|
|
|
|
|
i am trying to take multiple names by using getchar() but it only taking the first value and just skipping the rest.
here is the code.
#include <stdio.h>
int main()
{
char name[10][30], ch;
int i;
for(i=0; i<10; i++)
{
printf("Enter name: \n");
int j=0;
while(ch != '\n')
{
ch = getchar();
name[i][j] = ch;
j++;
}
name[i][j] = '\0';
}
return 0;
}
|
|
|
|
|
Because at the end of the first time round the while loop ch will contain the newline character, so every other loop will terminate immediately. You must remember to reset variables after you have finished with them. Please get yourself a good study guide on C and learn the language the proper way.
|
|
|
|
|
In addition to what Richard wrote, you have limited the names to 30 characters so make sure more than that are not entered.
|
|
|
|
|
|
i tried adding values to different addresses of arrays by using pointer but it doesn't work.
<pre>#include <stdio.h>
int main()
{
int i, num[10];
int *p;
p = &num[0];
for(i=0; i<=10; i++)
{
(p+i) = i;
printf("\n%d", *(p+i));
}
return 0;
}
|
|
|
|
|
Inside your for loop it needs to have this :
*(p+i) = i;
(p+i) is a pointer incremented by i. You have to dereference the pointer to save a value to where it is aiming.
|
|
|
|
|
if p = address of the num[0] then (p+i) is the address of the ith address and it is where i want to store the value, *(p+i) will give the value at that address i.e. de-referencing, below is the code i tried.
<pre>#include <stdio.h>
int main()
{
int i, num[10];
int *p;
p = &num[0];
for(i=0; i<=10; i++)
{
*(p+i) = i;
}
for(i=0; i<=10; i++)
{
printf("\n%d", *(p+i));
}
return 0;
}
|
|
|
|
|
You are very close. The problem now is your for loops are exceeding the capacity of num. It has 10 elements and your loops go from 0 to 10 inclusively. That is 11 elements - there is no num[11] item so that is a very bad thing.
I don't like literal values so I made the number a const and adjusted the loops :
const int Count = 10;
void main()
{
int i;
int num[Count];
int *p;
p = &num[0];
for( i=0; i < Count; i++ )
{
*(p+i) = i;
}
for( i=0; i < Count; i++ )
{
trace( _T( "item %d is %d" ), i, *(p+i) );
}
return 0;
} Your code looks quite a bit like C but this is a section for ATL/WTL/STL is about C++. If you are actually using C then this code won't compile. You can make Count a macro definition and then it will.
|
|
|
|
|
thank you. And here is the correct code.
<pre>
#include <stdio.h>
int main()
{
int i, num[10];
int *p;
p = &num[0];
for(i=0; i<10; i++)
{
*(p+i) = i;
}
for(i=0; i<10; i++)
{
printf("\n%d", *(p+i));
}
return 0;
}
modified 26-Dec-17 14:24pm.
|
|
|
|
|
|
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.
|
|
|
|