|
the code i posted prints the base file name not the path
I want to print the path without file name
|
|
|
|
|
|
you're right:
const char * path ="/work1/data/xxxx/yyy/file_name.txt";
char * basename;
char * filename;
basename = _strdup(path);
if ( !basename){}
filename = basename+strlen(basename);
while (filename != basename && *(filename) != '/')
filename--;
if ( filename != basename)
{
*(filename+1)='\0';
}
else
*basename='\0';
printf("%s\n", basename);
free(basename);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi
I have a class like:
class CMyclass1
{
public
CMyclass2 myclass;
.....
}
class CMyclass2
{
public
TCHAR Var[SOMEVALUE];
.....
}
CMyclass2 ::CMyclass2
{
memset(Var, '\0',sizeof(Var));
strcpy_s(Var,"some value");
}
----------- When I did following, program crashed ---
CMyclass1 * pclass = new CMyclass1()
delete pclass;
How can fix this problem?
Best regards,
|
|
|
|
|
There are 2 reasons:-
1. If you give SOMEVALUE=3 and copy "some value" it will fail and program will crash, so please check that.
2. what is need of memset when you are allocating in a stack?, Doing this also fails.
So handle heap allocation carefully.
|
|
|
|
|
Hi
I did following:
#define SOMEVALUE 100
Why this will cause problem?
I used "memset" to initialize the array. What else can I use to initialize an array?
So "memset" will use HEAP? I deleted the "memset", the bug is still there.
Best regards,
modified on Monday, July 13, 2009 9:51 AM
|
|
|
|
|
Use the debugger to step through the code to find the offending line. Aside from some syntax errors, your code works fine with VS6.
Using memset() is fine, although unnecessary in the context in which you are using it.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
I did following to solve the problem.
class CMyclass2
{
public
TCHAR* Var;
.....
}
CMyclass2::CMyclass2
{
Var = new TCHAR[SOMEVALUE];
}
VC++ does not allow TCHAR array in a class definition? Actually, TCHAR array is a pointer.
|
|
|
|
|
transoft wrote: VC++ does not allow TCHAR array in a class definition?
Sure it does.
transoft wrote: Actually, TCHAR array is a pointer.
It is now, but it wasn't earlier.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hi
Why it crashes when I use TCHAR array in the class definition and it works just fine when I use TCHAR pointer?
Thanks,
|
|
|
|
|
1) Your code works fine for me using VS6.
2) Define "crash." Have you isolated the offending line?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hey guys,
I've posted this question on other boards, but nobody has managed to suggest me the slightest of solutions.
I'm fairly new to programming C++ interfaces - I'm using Win32 API, not MFC. I know the basics through theForger's tutorial. Before coming to the programming world, I've been working as a web and graphical designer, which naturally makes me want to customize everything in my C++ applications. Specifically I want to decide how the window should look from the title bar to the minimize button to how individual buttons or tabs looks.
people do it with C#, for instance (A Professional Ribbon You Will Use (Now with orb!)[^]), but I can't seem to find anything that applies to C++ Win32 API.
If anybody knows where to find any tutorial or knows any keywords I might look up, I'd really appreciate it.
Thanks guys.
|
|
|
|
|
Look up "Owner Draw" windows and controls.
Using the Owner Draw method, you can make your windows and controls look like anything you want.
Also, by handling the Non-Client paint message in your windows, you can draw the title-bar, and borders just the way you want.
|
|
|
|
|
You can customize Windows using skinning.
Here is one such tutorial - Win32 Window Skinning[^]
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Guys,
Thanks so much. I think both your answers were what I was looking for - mostly, though, the Owner Draw.
Thanks so much, guys!
|
|
|
|
|
hello Friends
I updated my code from vs2002 to vs2008.I was using vector in that but in vs2008 it is getting crashed while pushbak in vector.
Is anything different in vs2008 fro vectors?
Thanks
Yogesh
|
|
|
|
|
yogeshs wrote: it is getting crashed while pushbak in vector
Care to supply some detail and possibly some minimal sample code?
yogeshs wrote: Is anything different in vs2008 fro vectors?
Iterators have changed, but that's implementation detail. The most likely thing is that your code does something a bit iffy that VS2002 doesn't care about but VS2008 does.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
here is the sample code in which i m using vector:
Piece is some class.
vector<piece> &m1 = mygarmentizemod->get_m1();
m1.clear();
for(;;)
{
m1.push_back(tmp);
}
tmp is the object of piece.
|
|
|
|
|
What are the template parameters of the vector? Also, if you have an infinite loop (which you have) I'm not surprised that you get an error - you're going to exhaust memory.
When you post a code sample, it helps if you a) select the "Encode HTML tags when pasting" option below the posting edit box and b) put it in a code block (select the code and then click the "code block" thing above the posting edit box.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
yogeshs wrote: Is anything different in vs2008 fro vectors?
Are you reading/writing to the vector from multiple threads? VS2002 had some sort of non-standard thread safety implementation. A few months ago I upgraded a HUGE project which was reading/writing to std:vector and std:map from VS2002 and the application showed absolutely no evidence of race conditions. Once I upgraded the project to VS2008 it was crashing everywhere. I ended up deriving a class from std:vector/std:map and using a mutex to synchronize reads/writes.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
How can i use IQueryAssociations interface to get all applications & its executable path associated to a specified file extensios such as .txt.
ie I mean , I wanted to a construct a list of applications associated to .txt file extesion.
thanks
Nitheesh
Jose Jo Martin
http://www.simpletools.co.in
|
|
|
|
|
Hello together,
I'm using VC++ 6.0 for developing a Unicode application. It works fine, but I have a problem with Unicode output in the debug window. As described everywhere, I checked "Tools->Options->Debug->Display Unicode strings" and I use the TRACE0, TRACE1, etc. macros. But Unicode characters are still shown as '?'.
Does anyone has a solution for this? Thanks in advance...
Kind regards
Marcus
|
|
|
|
|
Try displaying L"Unicode Text" from your program. If you see proper output, then it might probably be that the actual Unicode text (language) you're trying to display is not installed on your system.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Thank you for your reply Rajesh. Using L"..." shows correct characters if I just type Latin characters. If I use a message box then, for example, Russian characters are shown correctly but not for the debug window. Do you have any further advice for me?
Kind regards
Marcus
|
|
|
|
|
You're welcome, Marcus. Have you tried setting a valid Russian Unicode font as the default font for debugger output window? (I'm assuming that the language is installed on your machine, because you say it appears properly on a message box).
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|