|
Ahh, that's a horse of a different color.
If you tried separating the tokens using a space as the delimiter, an issue that I see is that the path\executable name can itself contain a space. This is usually resolved by surrounding that token with quotes. So as you are parsing the whole string, you'd need to keep track of whether you were in a quote or not. If so, then spaces do not count.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
Bingo!
Thank you!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Awesome. I had no idea such a routine existed.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Supposed I have a text file having the results of the 6/49 lottery in it:
49-05-13-42-18-45
43-24-36-16-39-22
32-48-05-18-34-29
13-14-07-41-48-39
47-05-17-13-37-49
06-23-34-21-46-37
06-42-13-40-11-37
39-44-40-21-32-20
17-26-38-43-01-02
How can I achieve the following output written to a text file with filename, "occurences.txt"?
49 - 2 times
49 paired with 13 - 2 times
I don't have an exact idea but maybe the following pseudocode can help:
void main ()
{
int number
cout<<"CHARACTER \t\ How many times it appeared"<<endl;
for (number='01'; number<='49'; number++)
{
cout<<number<<" - \t"<<countNumber(numbercount)<<" times"<<endl;
cout<<number<<" paired with \t"<<number<<" "<<ountNumber(numbercount)<<" times"<<endl;
}
system ("PAUSE");
return 0;
}
int countNumbers (int number)
{
ifstrem.stream; int numbercount;
int count=0;
stream.open ("countNumbers.txt"); stream.get (numbercount);
while (!stream.fail())
{
if (numbercount==number)
count++
stream.get(numbercount);
}
stream.close ();
return numbercount;
}
How can I go about this?
|
|
|
|
|
You cannot use character types that contain more than one character, like '49' . The first thing you need to do is read all the input, split the items into separate fields and convert the numbers to integers. You can then count the individual values, and the sets just by counting through all the saved numbers. You do not need to count from 1 to 49, since some of those values will not be present.
|
|
|
|
|
In additoon to what Richard said, you seem to be having a very vague understanding of C/C++ programming. Before trying your hand on a moderately difficult problem, you should really start with a tutorial on C++ programming. There are plenty of good sites on the web for this, e.g. at C++ Language - C++ Tutorials[^] You should specifically focus on the first chapter, which covers pretty much everything you need for the program you asked about.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
I'm sure there are many ways to skin this cat, but how about a loop that reads each line of the file into a string type, then calls string::find() for things like "49-" and "-49"? If one of those is found, then do something similar with the 13. Would that work?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Good afternoon
I am new in c++. I am trying to write a code that uses an array of 2 exponent 32, A small example is the code below.
#include <iostream>
# include <stdio.h>
# include <fstream>
# include <string.h>
# include <iostream>
#include <math.h>
# include <stdlib.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <limits>
#define two_power(n) (1u << (n))
using namespace std;
typedef unsigned long word32;
int main()
{
word32 delta, alfa;
static word32 array[4294967295][4294967295] ={0};
for (delta = 0; delta < 4294967296; delta++)
{
for (alfa = 0; alfa < 4294967296; alfa++)
{
array[delta][alfa] = alfa + delta;
}
}
cout << array[4294967295][4294967295];
return 0;
}
I there any method I can use to instead of using array because arrays have limitation in size. 2^32 = 4294967296. You can send me an email if you have an answer
kdmuthavhine@gmail.com
|
|
|
|
|
That is just crazy, you are trying to reserve 73,786,976,294,838,206,464 bytes in your program. And given that all your program does (or tries to do) is print the numbers from 1 to that value, it is rather a waste of time. You can use a single variable and write a loop that increments it from 1 to whatever final value you want, printing each value as it goes round the loop. You also do not need most of those #include statements; only include the ones you need.
|
|
|
|
|
So you need 73.78 x 10^18 bytes? Wow! May I ask what you're using it for?
Generally I'd use a vector instead of arrays and let the vector handle the memory allocations/deallocations, but I've never had to deal with numbers that large. I can't imagine your code being able to allocate that kind of space.
The program you've posted is accessing an invalid array index, the largest index you can theoretically have is array[4294967294][4294967294], because there are 4294967295 entries in each dimension, entries 0-4294967294.
"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
modified 24-Apr-20 13:23pm.
|
|
|
|
|
jeron1 wrote: because there are 4294967295 entries in each dimension
Yes but he's writing his program in the fourth dimension!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Because in the fourth dimension no one can hear your allocation fail?
"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
|
|
|
|
|
What does my question has to deal with facebook and drinking behaviour?
|
|
|
|
|
Member 14812342 wrote: What does my question has to deal with facebook and drinking behaviour?
Nothing.
It was not an answer, just a signature!
|
|
|
|
|
So what is it that has to be done. I want to create Differential Distribution Table (DDT) of Blowfish algorithm. I have done for DES.
|
|
|
|
|
for Differential Distribution Table of Blowfish algorithm
|
|
|
|
|
Well you cannot create it in memory like that. You need to rethink what you are trying to do and understand the hardware and software limitations of the system you are working on.
|
|
|
|
|
How does one invoke the File Explorer Properties dialog box in Windows 10 for a specific file from a C++ application?
EDIT:
You must use ShellExecute with a verb of "properties".
The difficult we do right away...
...the impossible takes slightly longer.
modified 24-Apr-20 10:52am.
|
|
|
|
|
Please read carefully.
I am not looking for RTFM replies.
I am getting nowhere in OpenGL forum.
I do understand this is NOT OpenGL forum.
I am NOT looking for fancy shading graphics,
I am not looking for how to retrieve object outline either.
I am looking for as detailed as possible practical flow in using OpenGL stencil.
I have bits and pieces and it is all just "try this ... try that..."
I am looking for help, not for pointless criticism of my coding style.
If you cannot help me , please dot not reply.
glPushAttrib( GL_ALL_ATTRIB_BITS);
// must clear all for resizing
// TOK resizing works !
glClear(
GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glClearStencil(0); // why and what ???
glEnable( GL_STENCIL_TEST); // TOK
// glStencilMask is set to 1 as default (??)
//glStencilMask(0x00); // no effect
//glStencilMask(0xFF); // no effect
{
// process object block is this correct place ??
OpenGL_Render_RealAxis(); // int parameter = 0)
OpenGL_Render_Plus_IMG_Axis(); //int parameter = 0)
OpenGL_Render_Minus_IMG_Axis(5); //passed temporary last circle as parameter 5 }
// TOK turn off writing to color buffer - do no show object to be stenciled
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
// Set the stencil buffer to write a 1 in every time
// a pixel is written to the screen
glStencilFunc( GL_ALWAYS, 1, 0xFFFF);
glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE);
{
// process block dupe
OpenGL_Render_RealAxis(); // int parameter = 0)
OpenGL_Render_Plus_IMG_Axis(); //int parameter = 0)
OpenGL_Render_Minus_IMG_Axis(5); //passed temporary last circle as parameter = 0)
}
parameter_stencil = 42; // verify stencil function
parameter_stencil = Stencil(parameter_stencil);
if (parameter_stencil == 0) {
printf(
"\nTOK HERE Stencil full circle parameter %i @function %s @line %i",
parameter_stencil, __FUNCTION__, __LINE__);
glStencilFunc(GL_EQUAL, 1, 1);
} // show / keep inside circle
else {
printf(
"\nStencil last circle parameter %i @function %s @line %i",
parameter_stencil, __FUNCTION__, __LINE__);
glStencilFunc(GL_NOTEQUAL, 1, 1);
} // keep all outside of stencil
// now showing all - stencil plus object ??
glFlush();
glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE);
glutSwapBuffers(); // no change !
|
|
|
|
|
Well you failed the first part of the flow you need to enable the stencil buffer before you clear it
glEnable(GL_STENCIL_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
From there the steps are
- Enable writing to the stencil buffer.
- Render objects, updating the stencil buffer.
- Disable writing to the stencil buffer.
- Render other objects
- display whole result
In vino veritas
|
|
|
|
|
I am sorry, but ALL buffers - display modes (?) are enabled in main OpenGl "event loop".
I though that glEnable(GL_STENCIL_TEST); // ENABLE the stencil buffer
is specifically to enable writing to the stencil buffer.
Am I wrong ?
window = glutCreateWindow("OpenGL - Base ");
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL);
I think I need to review all in old-fashioned "IBM flow chart" style - from top to bottom - from "vertex" to pixel on screen.
This OpenGL "pipe architecture" - from left to right - is just not working when it comes to stencilling.
What is confusing is mixing of hardwareand software.
"stencil works on pixel(s) "
Fore example
"stencil mask "defaults" to 1"
then I see stuff like this glStencilMask(0xFFFF);
I may also have modlelview stack messed-up.
|
|
|
|
|
Here is my latest code.
I'll try to delete my debugging stuff. Hope I 'll not delete something important.
The code basically works, it does apply the stencil - to show only data INSIDE the stencil circle.
BUT
ONLY when I enable viewing of the stencil AND data being written to the color buffer.
I have highlighted the code. I was under the impression this is ONLY for viewing the stencil, but apparently not.
Obviously I do not have to re-able the color buffer , hence I get BOTH - stencil and the stencilled "fragment".
I have no idea how to proceed and where is my error.
glClear(
GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glDisable( GL_STENCIL_TEST);
glEnable(GL_STENCIL_TEST);
glClearStencil(0x0);
glClear(
GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glStencilMask(GL_TRUE); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glStencilFunc(GL_ALWAYS, 1, 1);
parameter_stencil = 42;
parameter_stencil = Stencil(parameter_stencil); glFlush();
if (parameter_stencil == 0) {
printf(
"\nStencil full circle parameter %i @function %s @line %i",
parameter_stencil, __FUNCTION__, __LINE__);
glStencilFunc(GL_EQUAL, 1, 1);
} else {
printf(
"\nStencil last circle parameter %i @function %s @line %i",
parameter_stencil, __FUNCTION__, __LINE__);
glStencilFunc(GL_NOTEQUAL, 1, 1);
}
{
OpenGL_Render_Plus_IMG_Axis(); }
from here I am not sure how to display only the rendered fragment
I get both stencil and fragment ONLY when writing to color buffer is enabled
glStencilMask(GL_FALSE);
glClear(
GL_STENCIL_BUFFER_BIT );
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClear(
GL_STENCIL_BUFFER_BIT );
glFlush();
|
|
|
|
|
maybe professionals here at codeproject have a hint for me.
Please see following example:
#include <iostream>
using namespace std;
int c, d;
#define Circumference c
#define Diameter d
int main ()
{
cout << "Please enter diameter: ";
cin >> Diameter;
Circumference = 3.14 * Diameter;
cout << " Circumference is " << Circumference << endl;
return 0;
}
My IDE (Understand) report possibilities always break down the #define to it's origin. So all reports state that function main() uses variables 'c' and 'd'.
But what I like to have is the real used expression in the function source code. So report shoud show that main() uses 'Circumference' and 'Diameter' and not 'c' and 'd'.
Is there any tool out there (for Windows 10 OS) which is able to do this ?
Many thanks for any hint!
'There are 10 types of people in this world, those who understand binary and those who dont.'
|
|
|
|
|
I am not sure I understand what the problem is. I have just built and run your code successfully. But why are you doing it that way, what is wrong with: the following?
#include <iostream>
using namespace std;
int main ()
{
float Circumference;
float Diameter;
cout << "Please enter diameter: ";
cin >> Diameter;
Circumference = 3.14f * Diameter;
cout << " Circumference is " << Circumference << endl;
return 0;
}
|
|
|
|