|
locoone wrote: ...is there a list of all shortcuts in the registry somewhere?
I believe they are stored in special folders - check out SHGetFolderPath() API
This article may be helpful: CShortcut (Shell links to special folders)[^]
|
|
|
|
|
Hi all,
I need help with string functions in C.
Eg.,
const char *str1 = "Apple+Orange+Pineapple";
I need to crack the list above and get them as three different strings like
str2 = Apple
str3 = Orange
str4 = Pineapple
The "+" sign separates them.
How do I do it? Can anyone help? Thanks in advance.
|
|
|
|
|
strtok will tokenise a string ( split it based on a token ).
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks for your help. Is there a simple code snippet that you can send ?(if you have one). Thanks.
|
|
|
|
|
|
Thanks. was very helpful.
|
|
|
|
|
I assume you're writing in C (not cpp).
well, copy the lot to a buffer, and scan the string. Every time you find a '+' you replace it with a 0, and store the advanced pointer in the result atrray
e.g
int Breakup(char* str,char Sep,int nMax char* Result[]){
int i,j=0;
if(str==NULL)return -1;
int len =strlen(str);
char* buf=malloc(len);
if(buf==NULL)return -2;
Result[j++]=buf;
for(i=0;i<len;i++){
if(buf[i]!=sep)continue;
buf[i]=0;
result[j++]=buf[i+1];
if(j>=nMax)return nMax;
}
return j;
}
Don't be stuck, but thee's a lot to be said for CPP!
LateNightsInNewry
|
|
|
|
|
LateNightsInNewry wrote: copy the lot to a buffer, and scan the string. Every time you find a '+' you replace it with a 0, and store the advanced pointer in the result atrray
Why not just use strtok() ?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Why not just use strtok()?
Or maybe use strtok()
|
|
|
|
|
Mark Salsbery wrote: Or maybe use strtok()
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I figure if it's suggested enough times (as Christian suggested in the very first reply) then
maybe the OP will consider it. My reply should have been to the OP not to you sorry man!
|
|
|
|
|
Admittedly, Yes.
However, strtok is one of those obscure library functions on which I would spend more time debugging the peculiarities and hidden side effects, than what it would take to write it from the base up, in the knowledge of what one wants to achieve.
Once you get the picture in your head of what you want to achieve, I find raw pointer arithmetic an awfull lot clearer, and easier to debug, than the various ANSI library functions.
LateNightsInNewry
|
|
|
|
|
LateNightsInNewry wrote: However, strtok is one of those obscure library functions on which I would spend more time debugging the peculiarities and hidden side effects, than what it would take to write it from the base up...
Isn't that what looking at the CRT source code is supposed to address?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Yes, exactly the point I wanted to make.
LateNightsInNewry
|
|
|
|
|
I suspect everyone has run unti this, but I just ran into it.
double d1 = 1;
When I look at d1 in the debugger, it will show 1.0000001342, or something similar. Now, that is close to 1, but it's not the same as 1.
d1 - 1 is then equal to .0000001342.
And .0000001342 isn't zero.
Suggestions as to how to handle this? How do I get 1.0000000000 rather than 1.0000001342?
I know I can use an int for 1, but the same thing occurs with:
double d2 = 2.354
debugger shows d2 as 2.3540000154.
Thanks
|
|
|
|
|
I can't reproduce this on VC++ 2003 .NET SP1
|
|
|
|
|
It is inherant in how floating point works that many numbers cannot be precisely represented with a finite number of bits. Just as in base 10, a number such as 1/3 needs an infinite number of digits to be written out (0.33333.....)
Take, for example, the number 1/10. Suppose you write double d1 = 0.1 - internally this decimal is converted into binary which (simplfying somewhat, floating point numbers are actually stored in the binary version of scientific notation) is 0.0001100110011001100... where the bits to the right of the point at 1/2, 1/4, 1/8, 1/16, 1/32, etc. Since any actual data type has a finite number of bits (in the case of double precision floating point, 53 bits are available from the first "1") we can only store an apporximation of many values.
When using floating point data, you should never test numbers for equality (unless you're certain that the numbers need to be the same sequence of bits) you should instead check if the difference between two numbers is sufficently small.
|
|
|
|
|
AJR_UK wrote: It is inherant in how floating point works that many numbers cannot be precisely represented with a finite number of bits
So you're saying 1 can't be precisely represented in a double?
|
|
|
|
|
Bah, smart-alec. <pedantic>I only said "many numbers", I didn't say anything about which numbers, other than the example I gave.
1 (or any other integer until you get big enough that precision becomes an issue) can, of course, be precisely represented in a double. I dunno why Oliver was having problems when using the value 1, but I was addressing hte general case. That's my story, and I'm sticking to it
|
|
|
|
|
AJR_UK wrote: Bah, smart-alec
Sorry
Actually your post IMO was excellent and between you and Oliver you had me a bit worried
. I actually debugged a few examples and made sure!
Cheers!
|
|
|
|
|
I can't reproduce that, using Visual Studio 6.
Please give us info about your env.
|
|
|
|
|
I have following piece of code, which works in VC7 but not in VC6. Don't know what's the problem.
A.h
----
class A
{
private:
template[int N] //using sqare brackets as somehow while posting it ignores '<'
class B {
public:
B() {}
class C{
public:
C() {}
C* GetSomething() const;
}; //end class C
}; //end class B
};//end class A
A.cpp
------
template[int N]
typename A::B[N]::C*
A::B[N]::C::GetSomething() {}
RP
|
|
|
|
|
Possibly because VC6 is rubbish ? VC7 was a huge jump in standards conformance. It especially sucked at template support.
To get the < to show, check the 'ignore HTML tags' checkbox.
|
|
|
|
|
hello......
i need help for how to read/write file in C++
i use fstream but i wont to open file one time for all functions(file is glopal)
and i wont the file be open in the constructor of my class.
where can i declerd this lines
ftream myfile;
myfile.open(.....,.......);
is it in main or in class?
i have decler in main function but ather function be ERROR.
thanks for all.
|
|
|
|
|
This should be outside of any function or class:
fstream myfile;
This could be at the beginning of main():
myfile.open(.....,.......);
This could be at the end of main():
myfile.close();
Use this in other modules so they know where to link to myfile:
extern fstream myfile;
|
|
|
|