|
Hi,
Im trying to get this output in the console:
*
**
***
****
*****
******
*******
********
*********
**********
***********
With a genest loop.
How do i get those spaces?
I tried the ascii char '32', but that didn't work either.
Anyone any suggestion?
Thanks in advance!
Edit: its a triangle which is outlined to the right. Its not displayed correctly!
|
|
|
|
|
strange,
(char)32 or char(32) or you can use (' ') to write a space...
all should work
Mohammad
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|
Hi Mohammed,
Thanks for your reply.
I was kinda wondering how i can increase and decrease the spaces in a geneste for loop.
Do you know how i can do that?
|
|
|
|
|
I dont know what 'genest' mean - not even in the dictionary, so I assume it to mean 'nested loop', if this is true, then here is the code:
<br />
#include <iostream.h><br />
<br />
void main()<br />
{<br />
for (int i=0;i<10;i++)
{<br />
for(int j=0;j<5-i/2;j++)
cout<<' ';<br />
for(int k=0;k<i;k++)
cout<<'*';<br />
for(j=0;j<5-i/2;j++)
cout<<' ';<br />
cout<<endl;<br />
<br />
}<br />
}
hope this helps
Mohammad
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|
how do you display your spaces ??
don't printf(" "); do that correctly ?
|
|
|
|
|
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;
char diagram[][12] = { " *",
" **",
" ***",
" ****",
" *****",
" ******",
" *******",
" ********",
" *********",
" **********",
"***********" };
int main()
{
copy(diagram, diagram + 11, ostream_iterator<char*>(cout, "\n"));
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi Zac,
Thank you for your reply.
Isnt this possible to do this with 2/3 for loops?
|
|
|
|
|
Yustme wrote: Isnt this possible to do this with 2/3 for loops?
Possible? Yes. You can actually do it in 1 loop. I hardcoded the string for simplicity, but you can have that generated as well as print it to the screen all in 1 loop. However, there is no need to do so when you can use STL's built in algorithms to do it for you. Why write 15+ lines of code when 1 will suffice?
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi Zac,
This is an assignment of a book. Im learning C++ now and they are not that far yet.
Its chapter 3. All assignments are about loops, for loops in particular.
Thats why i wanna do this with a for statement.
|
|
|
|
|
Assuming you want to generate the strings as well as write them, you will do this then:
const unsigned int TRIANGLE_HEIGHT = 11;
for (int i = 0; i < TRIANGLE_HEIGHT; ++i)
{
for (int j = 0; j < TRIANGLE_HEIGHT; ++j)
{
if (j >= TRIANGLE_HEIGHT - i)
cout << '*';
else
cout << ' ';
}
cout << endl;
}
cout << endl;
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Yustme wrote: With a genest loop.
What kind of loop is this?
Yustme wrote: How do i get those spaces?
By using the spacebar, or ASCII 32. But since you did not show the code that is not working, we can't be of much help.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi David,
Here:
for( int k = 11; k > 1; k-- )
{
for( int g = 1; g < k; g++ )
{
cout << '*' ;
}
cout << endl;
}
|
|
|
|
|
So how are you expecting it to work with no cout << ' ' statement? What you've shown is just going to print asterisks.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Please anybody help me out ...... I have a rgb format video.. Its the collection of some frames. Now if I want to capture these frames one by one and display them at a particular frame rate, what should I do ??? Please help me out...
|
|
|
|
|
Look through codeproject articles / Multimedia.
If I remember correctly (which means "you go and have a look, don't expect others to do everything for you") there is at least one which deals with extracting frames from a video file. It may save them as separate bitmap images or something, but it makes a good starting point.
|
|
|
|
|
Hi, I am writing a C++ program. I have found out that an unhandled exception message will pop out whenever the code enters a function.
I have used breakpoints and cout statements to determine the point of the crash.
The function has 4 parameters. 1 int variable, 1 int array and 2 double arrays. "Tuples" and "Features" are constants representing values of 1600 and 46 respectively.
int rank(int num,int data[Tuples][Features],
double dist[Tuples],double rank[Tuples])
{ ..........
...........}
The program crashes after the first opening bracket. '{'. None of the statements inside the function are executed.
I don't know what is going on. How come the program will crash without even executing a statement?
|
|
|
|
|
How are you calling this function?
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
First, your crash is probably because your function is using too much stack memory. Too many local variables in the stack (or very large arrays on the stack).
Second, you may want to reconsider using multi-dimensional arrays.
|
|
|
|
|
If it's crashing at the point you mentioned, it's because it is unable to successfully process the parameters. Check David Crow's comments, I think he is probably right. Also, I am not sure, but check your syntax. I am not sure if I remember correctly, but when I learned C++, I was taught that you typically pass in an array as one parameter, and the subscripts as additional parameters - or something like that, I am not sure.
Anyway, you may want to use vectors instead.
I hope this helps.
Peace,
BP
|
|
|
|
|
KaKa' wrote: nt rank(int num,int data[Tuples][Features],
double dist[Tuples],double rank[Tuples])
change it to
int rank(int num,const int **data,const double *dist,const double * rank,int Tuples,int feature)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
How do you use this function?
|
|
|
|
|
Hi,thanks all for the replies. I think it could be a stack overflow because previously the 2D array was 128 rows by 46 columns but when I expanded it to 1600 rows, the program crashed.
So, if the the function parameters are replaced by pointers instead of arrays, will the crash problem be solved?
I call the rank function using this: rank(n,d,distance,r);
where n is the integer variable, d is the 2D array while distance and r are the 1D arrays.
|
|
|
|
|
Hi,
I have a small bit of C++ program, but I am not programmer in C++. Could anyone help me to explain or rewrite similar program in VB6??
This code is looking for this line in file:
DPB="FEFC52D7AE2930463046CFBA3146BBA8AF10AED2E858FFF2E7E9730F1BDB426A4174B6D67A4E86"
And then it is processing it. This line contains password (in this case is '000000000'), I think this line is a bit changed so it is incorrectly giving and answer. That's why I need to understand this C++ code to make a correction to a code and get correct password.
C++ program looks like this:
<br />
#include <stdio.h><br />
#include <windows.h><br />
#include <conio.h><br />
#pragma hdrstop<br />
#include <condefs.h><br />
<br />
#define BLOCK_SIZE 32768<br />
<br />
<br />
int memstr(const char *buf, const char *s, size_t size)<br />
{<br />
int off;<br />
const char *s_temp;<br />
<br />
if(!buf || !s || !(*s)) return -1;<br />
<br />
for(off = 0; off < size; off++)<br />
{<br />
for(s_temp = s; *s_temp != 0 && *buf == *s_temp; buf++, s_temp++)<br />
{<br />
off++;<br />
if(off >= size) return -1;<br />
}<br />
if((*(buf - 1) == *(s_temp - 1)) && *s_temp == 0) return off;<br />
buf++;<br />
}<br />
return -1;<br />
}<br />
<br />
LPSTR findEncryptPass(const char *filename)<br />
{<br />
FILE *prot_file;<br />
char *buff = 0, *s;<br />
size_t rc;<br />
int off;<br />
<br />
prot_file = fopen(filename, "rb");<br />
if(!prot_file) return 0;<br />
buff = (char *)malloc(BLOCK_SIZE);<br />
if(!buff) return 0;<br />
do<br />
{<br />
rc = fread(buff, 1, BLOCK_SIZE, prot_file);<br />
if(!rc) break;<br />
off = memstr(buff, "DPB=\"", BLOCK_SIZE);<br />
if(off < 0)<br />
{<br />
if(rc < BLOCK_SIZE) break;<br />
fseek(prot_file, -32, SEEK_CUR);<br />
continue;<br />
}<br />
fseek(prot_file, off - rc, SEEK_CUR);<br />
rc = fread(buff, 1, BLOCK_SIZE, prot_file);<br />
if(!rc) break;<br />
s = strchr(buff, '\"');<br />
*s = 0;<br />
return buff;<br />
} while(!feof(prot_file));<br />
free(buff);<br />
return 0;<br />
}<br />
<br />
void decryptPassword(const char *encrypt_pass, char *s)<br />
{<br />
char str[128], ch;<br />
char hs[] = { 0, 0, 0 };<br />
int v1, v2, i, l;<br />
int begin_found = 0;<br />
<br />
*s = 0;<br />
<br />
for(i = 0; encrypt_pass[i*2]; i++)<br />
{<br />
hs[0] = encrypt_pass[i*2]; hs[1] = encrypt_pass[i*2+1];<br />
v1 = strtol(hs, 0, 16);<br />
hs[0] = encrypt_pass[i*2+4]; hs[1] = encrypt_pass[i*2+5];<br />
v2 = strtol(hs, 0, 16);<br />
if(!begin_found)<br />
{<br />
if(v1 == v2) begin_found = 1;<br />
}<br />
else<br />
{<br />
if(v1 != v2)<br />
begin_found = 0;<br />
else<br />
{<br />
i += 3;<br />
break;<br />
}<br />
}<br />
}<br />
<br />
if(!begin_found) return;<br />
<br />
for(ch = 0, l = 0; encrypt_pass[i*2+2]; i++, l++)<br />
{<br />
hs[0] = encrypt_pass[(i-2)*2]; hs[1] = encrypt_pass[(i-2)*2+1];<br />
v1 = strtol(hs, 0, 16);<br />
hs[0] = encrypt_pass[i*2]; hs[1] = encrypt_pass[i*2+1];<br />
v2 = strtol(hs, 0, 16);<br />
ch = (ch + (char)v1) ^ (char)v2;<br />
str[l] = ch;<br />
}<br />
str[l] = 0;<br />
CharToOem(str, s);<br />
}<br />
<br />
#pragma argsused<br />
int main(int argc, char **argv)<br />
{<br />
char s[128];<br />
char *encrypt_pass_str;<br />
<br />
if(argc < 2)<br />
{<br />
printf("Usage: vbakey.exe filename\n");<br />
return 1;<br />
}<br />
<br />
if(!(encrypt_pass_str = findEncryptPass(argv[1])))<br />
{<br />
printf("Password not found\n");<br />
return 1;<br />
}<br />
<br />
decryptPassword(encrypt_pass_str, s);<br />
printf("File password: %s\n", s);<br />
free(encrypt_pass_str);<br />
printf("Press any key for continue ... \n");<br />
getch();<br />
return 0;<br />
}<br />
This is whole program. And I don't need any conversion or explanation on how to get arguments for file neither about function 'findEncryptPass' which I assume will return in this case "FEFC52D7AE2930463046CFBA3146BBA8AF10AED2E858FFF2E7E9730F1BDB426A4174B6D67A4E86". I am most interested in function 'decryptPassword'. How it works and what it returns.
Thanks for any help.
|
|
|
|
|
Tomazas77 wrote: That's why I need to understand this C++ code...
Using the debugger will go a long way towards this.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I don't have C++ debugger. That's way I am asking for help.
|
|
|
|
|