|
Hi everyone, I have such a task: "Given an integer square matrix. Determine the minimum among the sums of diagonal elements parallel to the main diagonal of the matrix." I have a code but I have problems compiling a flowchart for it, can you help me with compiling a flowchart or give tips? thanks in advance
thats my code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N_MIN -3
#define N_MAX 5
int main(int argc, char *argv[]){
int s,i,j,k,l,s1,t2,t1;
int a[5][5];
srand(time(NULL));
for(i=0;i<5;i++){
for(j=0;j<5;j++){
a[i][j]=rand()%(N_MAX-N_MIN+1)+N_MIN;
}
}
for(i=0;i<5;i++){
for(j=0;j<5;j++){
printf("%3d ",a[i][j]);
}
printf("\n");
}
k=0;
s=0;
l=0;
for (i=0; i<5; i++){
for (j=0; j<5; j++){
if (a[i][j]>=0){
if(a[i][j]%2==0)
l+=a[i][j];
k++;
}
}
if (k==5){
l=l;
}
else {
l=0;
}
s=s+l;
k=0;
}
s1=a[0][5-1];
for(i=1; i<5; i++){
t1=t2=0;
for(j=0; j<5-i; j++){
t1+=a[i+j][j];
t2+=a[j][i+j];
}
if(t1<s1) s1=t1;
if(t2<s1) s1=t2;
}
printf("vivod %d %d\n", s,s1);
return 0;
}
|
|
|
|
|
Can you write a line by line description of what this code does? Is this a question about the C language or or the typical symbols in flowcharts or something else?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Start by simply describing in english what each code section does, the flowchart will fall out from that.
It will only be a problem if you didn't write the code yourself
In vino veritas
|
|
|
|
|
I have migrated an application in vc++ application from VS2010 to VS2017 Professional.
I am able to build it successfully. But it the time of execution, it shows me below error:
'SiMDICnvs.exe' (Win32): Loaded 'C:\svn_wa\Wbcode\Trunk\Projects\SiMDICnvs\Debug\SiMDICnvs.exe'. Symbols loaded.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp_win.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbase.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mfc140d.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\win32u.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32full.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxtheme.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\gdi32.dll'
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.17134.1304_none_9d23a7c03adb3d0b\comctl32.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
'SiMDICnvs.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\ucrtbased.dll'
The thread 0x363c has exited with code -1073741515 (0xc0000135).
The thread 0x28dc has exited with code -1073741515 (0xc0000135).
The program '[3376] SiMDICnvs.exe' has exited with code -1073741515 (0xc0000135) 'A dependent dll was not found'.
Editor: moved to the C++ forum from the suggestions forum
modified 17-Mar-20 7:25am.
|
|
|
|
|
Wrong place to post this: this is for reporting and discussing problems with this site, not with your software.
Try here: Ask a Question[^] or here: C / C++ / MFC Discussion Boards[^]
But ... remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. So give us as much relevant info as you can - like what you found when you looked at those locations, perhaps...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
All the PDB file stuff isn't errors it's just the debugger telling you it can't debug inside the windows dll. You need the non community version for that aka the paid version
The actual error is you don't have the comctl32.dll loaded. I could give you the long explanation of where you add it in the program options but lets give you the new hack way
Simply place this near the top of your main file
#pragma comment( lib, "comctl32.lib" )
In vino veritas
modified 17-Mar-20 21:33pm.
|
|
|
|
|
I think I almost got it right. I have a question about the two file reads
if( cf.Read( &BFH, sizeof( BITMAPFILEHEADER ) )
!= sizeof( BITMAPFILEHEADER ) ||
BFH.bfType != 'MB' ||
cf.Read( pDib, dwDibSize ) != dwDibSize )
first it will read the first 14 bytes which is the header and store it in BFH, at the second read it will read a chunk of data but from the looks of it that chunk will include the (first) header again along with whatever else is included
modified 15-Mar-20 4:13am.
|
|
|
|
|
No, the second read will start from the byte following the position where the previous read stopped. That is normal file IO operations. It will only re-read the header if you rewind the file after the first operation.
|
|
|
|
|
 This is my write attempt.
BITMAPFILEHEADER BFH;
BITMAPINFOHEADER BIH;
RGBQUAD Palette;
RGBQUAD * Pixels = new RGBQUAD[10];
cf.Read( &BFH, sizeof( BITMAPFILEHEADER ));
cf.Read( &BIH, sizeof( BITMAPINFOHEADER ));
for(int i =0; i<10; i++)
{
cf.Read(&Pixels[i],sizeof(RGBQUAD));
}
StringCchPrintfA(message,1024,"b0 is %d", Pixels[0].rgbBlue);
MessageBox(NULL, message, "Textures.exe", MB_OK);
StringCchPrintfA(message,1024,"g0 is %d", Pixels[0].rgbGreen);
MessageBox(NULL, message, "Textures.exe", MB_OK);
StringCchPrintfA(message,1024,"r0 is %d", Pixels[0].rgbRed);
MessageBox(NULL, message, "Textures.exe", MB_OK);
StringCchPrintfA(message,1024,"r1 is %d", Pixels[1].rgbRed);
MessageBox(NULL, message, "Textures.exe", MB_OK);
StringCchPrintfA(message,1024,"g1 is %d", Pixels[1].rgbGreen);
MessageBox(NULL, message, "Textures.exe", MB_OK);
StringCchPrintfA(message,1024,"b1 is %d", Pixels[1].rgbBlue);
MessageBox(NULL, message, "Textures.exe", MB_OK);
CFile fileWrite;
Pixels[0].rgbBlue = 100;
Pixels[0].rgbGreen = 100;
Pixels[0].rgbRed = 50;
if( !fileWrite.Open( pszFilename,
CFile::modeCreate | CFile::modeWrite ) )
return( FALSE );
fileWrite.Write( &BFH, sizeof( BITMAPFILEHEADER ) );
fileWrite.Write( &BIH, sizeof( BITMAPINFOHEADER ) );
for(int i =0;i<10; i++)
{
fileWrite.Write( &Pixels[i], sizeof( RGBQUAD ) );
}
when I start my program again I expect the values of the first pixel to be updated but they aren`t
|
|
|
|
|
The code looks valid enough, are you sure the file is getting created correctly?
|
|
|
|
|
you`re right, if I try to create the file under a new name it works.
|
|
|
|
|
I have just tried a similar exercise and the changes are correctly made to the output file.
|
|
|
|
|
I will run into other C related issues, you`re not getting rid of me.
|
|
|
|
|
Don't worry, I have the freedom to ignore any messages that don't interest me.
|
|
|
|
|
You are confused there are two headers one after another you need to read them both before deciding whether to do step 3 and I have put a few hints what you need to do
1.) Read BITMAPFILEHEADER check for "BM", hold offset to bitmap data
2.) Read BITMAPINFOHEADER calc DWORD line stride width from bitmap width and bitdepth, see if you have a palette if so do step 3 else step 4
3.) Read the index palette if the BMP has one
4.) Jump to file offset from step 1 that is your bitmap data. Now you need to remember each line is DWORD (4 byte aligned) that means if you multiply the bytes per each line pixel * bitmap width it has to equal 4. So lets give you an example if you bitmap is 24Bit so each pixel is 3 bytes. So if your image was one pixel in width the first line is the first 3 bytes then there is a pad of one dummy byte and the second line starts at the 4th byte. So there can be 0 to 3 extra bytes per line because each new line must start on a DWORD boundary. So the amount of data you need to read for a line can be a couple bytes more than the just multiplying the bitmpap width * bytes per pixel.
The dummy bytes are usually zero but some smart people worked out long ago if you make all your images odd so you have the extra bytes you can put a hidden watermark, or play spy and put secret messsages in the dummy bytes
In vino veritas
|
|
|
|
|
Richard I have it working. Now on to saving.
phil, leon thanks guys.
|
|
|
|
|
I fount a class to read and write bitmaps, it`s old source code that uses MFC. it uses CFile to read and write, when I try to compile I get a Quote: WINDOWS.H already included message. Is there a way to work around the problem?
modified 11-Mar-20 13:07pm.
|
|
|
|
|
fearless_ wrote: Is there a way to work around the problem? Yes, remove the duplicate include statement.
|
|
|
|
|
thanks, with a simple tweak at headers it worked
|
|
|
|
|
Would you mind helping me further? I loaded the bitmap, however when I check the values from the array into which the bitmap is loaded they show up as 0 (null).
modified 12-Mar-20 4:05am.
|
|
|
|
|
Really. And we are supposed to guess what code and where the error occurs?
|
|
|
|
|
here is my code
StringCchPrintfA(pszFilename,1024,"hello.bmp");
if( !cf.Open( pszFilename, CFile::modeRead ) )
{
StringCchPrintfA(message,1024,"error reading file");
MessageBox(NULL, message, "Textures.exe", MB_OK);
return( FALSE );
}
DWORD dwDibSize= cf.GetLength() - sizeof( BITMAPFILEHEADER );
int bsize =0;
bsize= cf.GetLength() - sizeof( BITMAPFILEHEADER );
StringCchPrintfA(message,1024,"bitmap size %d",bsize);
MessageBox(NULL, message, "Textures.exe", MB_OK);
unsigned char *pDib;
pDib = new unsigned char [dwDibSize];
if( pDib == NULL )
{
StringCchPrintfA(message,1024,"error allocating array ");
MessageBox(NULL, message, "Textures.exe", MB_OK);
return( FALSE );
}
BITMAPFILEHEADER BFH;
try{
if( cf.Read( &BFH, sizeof( BITMAPFILEHEADER ) )
!= sizeof( BITMAPFILEHEADER ) ||
BFH.bfType != 'MB' ||
cf.Read( pDib, dwDibSize ) != dwDibSize )
{
StringCchPrintfA(message,1024,"error processing the file ");
MessageBox(NULL, message, "Textures.exe", MB_OK);
delete [] pDib;
return( FALSE );
}
}
modified 12-Mar-20 8:41am.
|
|
|
|
|
And what is the problem and where does it occur?
And please use proper <pre> tags so your code is formatted properly. The code button at the top of the edit box provides proper formatting for most languages.
|
|
|
|
|
At the end of code posted above I try to do this:
StringCchPrintfA(message,1024,"dib at 34 %d",pDib[34]);
MessageBox(NULL, message, "Textures.exe", MB_OK);
I expect pDib[34] to be 255 since the bitmap is 10 white pixels ( in a row) 40 bytes in total.
|
|
|
|
|