473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

char to TCHAR

6
Below are my codes,and I want to use TCHAR to replace the char

/****************************************
const char* ptr = NULL;
char newPath[100];

ptr = strrchr(absPath, '.');
strncpy(newPath, absPath, ptr - absPath + 1);
newPath[ptr - absPath + 1] = '\0';

*******************************************/

Below are modified codes with some logic errors, anyone can tell me what's wrong?

/*******************************************
const TCHAR* ptr = NULL;
TCHAR newPath[100];

ptr = _tcsrchr(absPath, _T('.'));
_tcsncpy(newPath, absPath, ptr - absPath + 1);
newPath[ptr - absPath + 1] = (const TCHAR) _T('\0');

********************************************/
Thanks for your answers!
Dec 3 '08 #1
2 13194
donbock
2,426 Expert 2GB
It would help immensely if you told us what errors are being reported by the compiler or what run-time misbehavior you're seeing.

Did you include the TCHAR header? (I think it is called tchar.h)
Dec 3 '08 #2
97612
6
Dear donbock,

Thanks for your reply, my problem is solved , thanks!

Below are the working code:

const TCHAR* ptr = NULL;
TCHAR newPath[100];

ptr = _tcsrchr(absPath, _T('.'));
_tcsncpy(newPath, absPath, ptr - absPath + 1 );
newPath[ptr - absPath + 1] = TCHAR('\0');
Dec 8 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Markus Hämmerli | last post by:
I ' ll tra to convert a Cstring to char* without success. I working in a Unicode enabled environment this is working in Unicode CString source = _T("TestString"); TCHAR *szSource =...
4
by: muroogan | last post by:
I read a text file into a char variable char tchar; I want to trim leading spaces (Left trim).How can I do that in C++. Any input will be appreciated.
37
by: Debajit Adhikary | last post by:
Now I know (from Stroustrup's site) that "char" is pronounced "tchar" and not "kar". Does the same hold true largely in the C world?
16
by: AA | last post by:
I am trying to print a table of what integer corresponds to what character. Can someone please tell me what is wrong with this code? #include <stdio.h> int main() { char line; /* each...
5
by: Joe Thompson | last post by:
Hi, I am using VS.net 2003 to write a managed C++ windows application. My main form traps the WM_DEVICECHANGE message and calls a method in my own unmanaged class passing the wParam and lParam....
3
by: Kevin Frey | last post by:
I am porting Managed C++ code from VS2003 to VS2005. Therefore adopting the new C++/CLI syntax rather than /clr:oldSyntax. Much of our managed code is concerned with interfacing to native C++...
2
by: Bill Maclennan | last post by:
Hi, Part of my code receives data in a char array, with pairs of characters representing a hex value - e.g. Array = "1234abcd" really represents 0x12, 0x34, 0xab, 0xcd. I need to convert the...
11
by: Angus | last post by:
I am working with a C API which often requires a char* or char buffer. If a C function returns a char* I can't use string? Or can I? I realise I can pass a char* using c_str() but what about...
5
by: T. Crane | last post by:
Help! I am trying to figure this out, and I have the impression that it should be really easy, but I'm at a loss. Here's my problem: I want to take the output from const char *...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.