|
Yes, in case 1 the compiler assumes the name of the array actually means a pointer to the first element. In case 2 you have specifically requested "pass the address of the first element of the array".
|
|
|
|
|
Thanks
When you can do the same thing in several ways something is not right
|
|
|
|
|
fearless_ wrote: When you can do the same thing in several ways something is not right
I can only imagine the following program will blow your mind:
#include <stdio.h>
int main()
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7};
int i1 = a[2];
int i2 = 2[a];
printf("i1 = %d i2 = %d\n", i1, i2);
return 0;
}
Keep Calm and Carry On
|
|
|
|
|
I would also pass the size of the array to the function instead of hard-coding it at 10 :
int Function(int* arrayargument, size_t size)
|
|
|
|
|
I was trying to keep the example as simple as possible. But since we`re here, what`s size_t? It`s the second time I see someone using it, is it an actual variable or just a custom?
modified 28-Apr-20 11:04am.
|
|
|
|
|
size_t is just a type. Like int, long, and so on
|
|
|
|
|
Thanks Victor
you mean a built-in type in a c++ compiler? what makes it particular, with float the compiler will let you use the comma, char is a like a tiny int, what makes size_t special?
modified 28-Apr-20 16:22pm.
|
|
|
|
|
|
oh so it`s a class object from a library not a built in type.
modified 29-Apr-20 16:34pm.
|
|
|
|
|
|
Are you bored? don`t be, I`m learning
|
|
|
|
|
Don't worry! Just learn!
And sorry if I wrote something wrong here!
|
|
|
|
|
|
The wininet library in Windows contains APIs for "cracking" and parsing network URIs into their component parts.
Are you aware of any facility in Windows that performs this function for command lines? (Something that I can call from an application, not the parsing that is done when my application is launched.)
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Are you talking about the contents of argc and argv ?
"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
|
|
|
|
|
Yes, and the executable name.
I imagine each argument separated into an array, and the executable name separated.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard Andrew x64 wrote:
I imagine each argument separated into an array, and the executable name separated. All of that is contained in the argv vector. For the executable name, look at the 0th item.
For WinMain() , you may have to refer to __argc and __argv instead.
"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
|
|
|
|
|
Thank you David.
I didn't make it clear enough at first. I meant that I want my application to be able to parse the command line of a separate process.
You know how some registry keys have command lines in them? I was wondering if there is something built into Windows that can make it easy to parse them.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
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)
|
|
|
|