|
This works perfectly! I have not yet understood how it works though but will think on it.
I was thinking on the idea to print the top row of the matrix then rotate the matric anticlockwise while removing the top row and printing the next top row and so on. But then I needed a function to rotate the matrix anticlockwise, which was not easy to implement when you consider you have to eliminate the top row as well. Your code is much simpler and very neat. I still have to understand it fully though. What do you think about my idea. Can you explain a little bit of your code.
Thanks a lot for sharing
|
|
|
|
|
Happy to be of help.
About rotating the matrix, it would take more time and more space, so I think it's not a good solution.
Yeah I know that my code wasn't that readable, C pointer math can be hellish...
It works by using a single iterator on rows r . This iterator goes from the first row (0) to the middle row ((rows/2)-1).
First I print the row pointed by r:
for (i=r; i<(columns - r); i++) printf("%d ",array[(r*columns)+i]);
then I proceed printing the rightmost column, starting from the last item I printed for row r :
for (i=r+2; i<=(rows-r); i++) printf("%d ",array[(i*columns)-1-r]);
I continue with the lowest row, which is printed right to left:
for (i=(columns-r-2); i>=r; i--) printf("%d ",array[((rows-r-1)*columns)+i]);
and finally with the first column, bottom to top:
for (i=rows-r-2; i>r; i--) printf("%d ",array[(i*columns)+r]);
With each iteration r grows by one. You will see that it's used in all the for loops, in order to move them towards the centre of the matrix one row and one column each.
Hope it's more clear now, if you think it would help I can rewrite this using distinct row and column indexes on the array, in order to make it clearer.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Thanks for explaining. I got the idea. This is a beautiful logic but it also requires some arithmetic and pointer skills If you could implement it in general arrow notation, that would be great. But of course not required
You are absolutely right, the rotate array matrix approach would be too much waste of time and computationally expensive.
I think this is great logic. I would not have seen it unless it was implemented.
Thanks again. I greatly appreciate your help
BTW Brave for implementing it in such a short amount of time!
|
|
|
|
|
No problem, here is the version with separated row and column indexes:
#include <stdio.h>
void PrintArrayClockwise(int array[][4], int rows, int columns)
{
int r = 0;
int rh = rows / 2;
int i;
while (r < rh)
{
for (i=r; i<(columns - r); i++) printf("%d ",array[r][i]);
printf("\n");
for (i=r+1; i<(rows-r); i++) printf("%d ",array[i][columns-r-1]);
printf("\n");
for (i=(columns-r-2); i>=r; i--) printf("%d ",array[rows-r-1][i]);
printf("\n");
for (i=rows-r-2; i>r; i--) printf("%d ",array[i][r]);
printf("\n");
r++;
}
}
int main()
{
int numbs[4][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
PrintArrayClockwise(numbs, 4, 4);
return 0;
}
Unluckily there's no way of passing a bydimensional array to a function without indicating the second dimension, at least none that I know of (but my ansi C is VERY rusty hehe). It sure can be done with int** anyway.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Thanks again! I appreciate it. I am definitely a fan of your programming skills. How much of experience do you have in programming btw. You have personnel contact?
|
|
|
|
|
Huh well thanks, you are definitely overvauling me hehe.
I'm into programming ever since I was 11 (started with a Philips game console which could be programmed in a kind of pseudo-assembler, then a year later I passed to a C64 and so on - typical for my generation), and have been working as a software engineer ever since 1989. Quite some time I'd say. :P
Don't get me wrong, but I won't be giving my personal contact in a forum. I've nothing against you in particular, but it's simply not good practice!
If you ever need any more help post here. If I'll be able to help I'll gladly do it, or someone else will. Besides, forums are good also for other people, who can learn by reading the answers to your questions.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Good to know a little bit about you. I actually looked at your webpage on codeproject but there was not much there except that you are from Italy Well thanks for the little background. Codeproject is my resource for technical questions so I will definitely post here if i need any help.
Thanks again.
|
|
|
|
|
Hi
I want to copy needed dlls into an autorun CD that runs a VC++ 2008 exe
I don't want to install the Redistributable Package.
I tested it with dependency walker and copied all needed dlls for MFC app, but it did not worked!
(but I do it easy for VC++2003 exe!)
What other thing I must do?
Thanks
www.logicsims.ir
|
|
|
|
|
build the program statically linked.
Project Properties / Config Properties / general / Use Of MFC = Use MFC in a static library
|
|
|
|
|
I know it, Thanks
but I don't want to link it statically.
www.logicsims.ir
|
|
|
|
|
This is all due to the horribly designed side-by-side crap Microsoft started pushing with Windows 2000 (though it didn't really work until XP.) With SxS, you have to put your DLLs in the correct install spots (meaning let Microsoft's installer do it.) There are other solutions, but I've forgotten the rules. Here's one article on the subject (I neither endorse or condemn this article--I breezed through it):
http://69.10.233.10/KB/cpp/PrivateAssemblyProjects.aspx[^]
Do searches on "side-by-side" and/or SxS with MFC and DLL and you will start getting hits [on the nightmare Microsoft created.]
|
|
|
|
|
Thank you so much
www.logicsims.ir
|
|
|
|
|
You need to add a manifest to the app (either as a separate file or in the application resources) that tells Windows to look in the application folder for the C runtime libraries. See the Deploying Visual C++ library DLLs as private assemblies section on this page[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
What is the C++ syntax for "typeof(string)"? I'm patterning after the following line from SourceGrid sample #14.
SourceGrid.Cells.Editors.ComboBox cbEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(string));
I'm trying to setup a SourceGrid text editor in C++. I don't know how to make the constructor in the following statement.
SourceGrid::Cells::Editors::TextBox^ textEditor = gcnew SourceGrid::Cells::Editors::TextBox(???);
|
|
|
|
|
Into C++/CLI typeof(Something) goes to Something::typeid .
You should post this kind of questions into Managed/ C++ CLI forum.It's native coding forum.
Life is a stage and we are all actors!
|
|
|
|
|
Thanks, this works...and I'll try harder to deal with the concept of being managed when I use this stuff.
String^s="";
SourceGrid::Cells::Editors::TextBox^ textEditor =gcnew SourceGrid::Cells::Editors::TextBox(s->GetType());
|
|
|
|
|
HI,
I we go to Control panel->Network Connections we can see all the network addaptors present in the system. If we double click and connected network adaptor it will show us a status dialog box for that connection.
I am trying to open that status dialog through my application which is written in C++ using win32 programming concept.
Can any body has any idea? How to acheive this?
Birajendu
SonicWALL
Bangalore
India
|
|
|
|
|
Do you need to InternetGetConnectedStateEx ? and also see Showing Dial-up Connection Status Window[^].
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
For these sorts of things, see on Win32 ng[^]
(some Win32 gurus have Windows source code...)
|
|
|
|
|
hey every one, i got a problem about the customize the open file dialog(which use the openfinename)
when i open a open file dialog, i want the open file dialog can open in the detail mode(the default is the list style),
and in the detail mode, the syslistview32 show four columns{file name, type, size, and modify time}, but i wand add a create time or author column(whatever), i donot know how to do it
at first i a a hook function to the opnefilename, and in the hook function's wm_notify message, i got the syslistview32 and sysheader32 handle.and send message wm_command to sysheader32 handle to set the initialion view style(like list, thumnbail, icon or detail), this job i had done.
but how can i add a new column to the syslistview32 or sysheader32?at first i simulate a right click message to the sysheader32. like
NMHDR mnh;
mnh.hwndFrom = hHeader32;
mnh.code = MN_RCLICK;
SendMessage(hListview32, WM_NOTIFY, 0, (LPARAM)&nmh);
the code can pop up the menu, but i dont know how to get the handle to the pop up menu.
so i canot simulate another menu click message.
any thing i wrong? or how can i add a new column(author or create date) under the detail view style before the open file dialog show?
my english is so poor, i hope you can understand.
thank you any way.
|
|
|
|
|
Actually I want to resize child windows.
Parent window has 2 horz child windows (in 2 rows), separator between 2 child windows are not very thin (not as border of CSplliteWnd) and its height is fixed, and images are displyed on the separator.
which looks like this:
------------------------
| child window |
| |
| |
| |
------------------------
| separator | X |
| | |
------------------------
| child window |
| |
| |
| |
------------------------
I hope to find a control and put it at X place, then user can use mouse to drag-drop the control to resize the 2 related child windows along vertical direction.
Mouse can move vertically only and not over top and bottom of 2 related child windows (or top and bottom of parent window).
Any comments?
Is there a contral like this?
Thanks
|
|
|
|
|
So, I got a little bored and decided to create a desktop locker through the screensaver function of windows. I'm running XP and Dev C++ 4.9.9.2 and Dev is causing my problem. Other places I've checked said i would need to link "comctl32.lib" which I can't seem to locate on my computer or the internet for download. Incase it would be of any use I'll post my program code.
#include <iostream>
#include <windows.h>
#include <scrnsave.h>
unsigned char new1;
using namespace std;
LONG WINAPI ScreenSaverProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
switch(message)
{
case WM_CREATE:
return 0;
case WM_ERASEBKGND:
return 0;
case WM_TIMER:
uTimer = SetTimer(hwnd, 1, 1000, NULL);
return 0;
case WM_DESTROY:
KillTimer(hwnd, uTimer);
PostQuitMessage(0);
return 0;
}
return DefScreenSaverProc(hwnd,message,wparam,lparam);
}
BOOL WINAPI ScreenSaverConfigureDialog(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
return true;
}
BOOL WINAPI RegisterDialogClasses(HANDLE hmodule)
{
return true;
}
I receive an error with the "uTimer = SetTimer(hwnd, 1, 1000, NULL);" line of code, but I'm assuming that its linked to the comctl32.lib considering I read scrnsave.h requires it; also the code compiles but does not work without the uTimer line.
|
|
|
|
|
Suposedly comctl32.lib comes with Microsoft's Platform SDK (you can download that from the MS site), i checked on my system and it sits in "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib" (yes, yes, i am still using VS2003, so sue me ), so the platform SDK thing seems to be right. No idea if you can use that with Dev C++ or not...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
SetTimer is linked in via user32.dll, not the common controls library. Do you have any of the Windows Platform SDKs installed? (I'm not sure what Dev C++ comes with as far as built-in libraries...)
Adam Maras | Software Developer
Microsoft Certified Professional Developer
|
|
|
|
|
No I don't have the SDK platforms, I have VS2008 on another computer or older harddrive somewhere but I have no idea which one and don't exactly prefer using VS over Dev.
|
|
|
|
|