|
-
September 1st, 2006, 03:51 AM
#1
Convert TCHAR[][] to char*?
Hi folks
I want to convert TCHAR[][] to char* and TCHAR[][][] to char*. help me.
If I Helped You, "Rate This Post"
Thanks
Guna
-
September 1st, 2006, 04:37 AM
#2
Re: Convert TCHAR[][] to char*?
That do you mean? char[][] and char* are not the same, less char[][][] and char*.
-
September 1st, 2006, 04:42 AM
#3
Re: Convert TCHAR[][] to char*?
Code:
TCHAR tc[2][2];
char* pChar;
pChar = (char*)&tc;
-
September 1st, 2006, 04:57 AM
#4
Re: Convert TCHAR[][] to char*?
 Originally Posted by cilu
That do you mean? char[][] and char* are not the same, less char[][][] and char*.
sorry cilu i didn't get u.
If I Helped You, "Rate This Post"
Thanks
Guna
-
September 1st, 2006, 04:59 AM
#5
Re: Convert TCHAR[][] to char*?
 Originally Posted by dave2k
Code:
TCHAR tc[2][2];
char* pChar;
pChar = (char*)&tc;
i try this code but it onlt take first char only.
If I Helped You, "Rate This Post"
Thanks
Guna
-
September 1st, 2006, 05:02 AM
#6
Re: Convert TCHAR[][] to char*?
Hi
I have solution for this problem ,
VOID ChartoTChar(TCHAR *CBuff,CHAR *Char)
{
while((*CBuff++ = (TCHAR) *Char++) != '\0');
}
void WcharToString(char * str,TCHAR* pTchar)
{
while( (*str++ = (char)*pTchar++) != '\0') ;
}
It will usefull for u.
-
September 1st, 2006, 09:17 AM
#7
Re: Convert TCHAR[][] to char*?
 Originally Posted by luckykiran
Hi
I have solution for this problem ,
VOID ChartoTChar(TCHAR *CBuff,CHAR *Char)
{
while((*CBuff++ = (TCHAR) *Char++) != '\0');
}
void WcharToString(char * str,TCHAR* pTchar)
{
while( (*str++ = (char)*pTchar++) != '\0') ;
}
It will usefull for u.
And what does this have to do with the question?
-
September 1st, 2006, 09:19 AM
#8
Re: Convert TCHAR[][] to char*?
 Originally Posted by Gunaamirthavelu
sorry cilu i didn't get u.
Well, I didn't get you either. Perhaps you should explain what are you actually trying to do. You want to convert and array or arrays of chars to a pointer to char and an array of arrays of arrays of char to pointer to char. What do you want to do?
-
September 1st, 2006, 09:49 AM
#9
Re: Convert TCHAR[][] to char*?
 Originally Posted by Gunaamirthavelu
I want to convert TCHAR[][] to char* and TCHAR[][][] to char*. help me.
Why do you feel the need to perform this conversion?
Please post the code where (you think) such conversions are necessary.
We here might have another opinion...
-
September 7th, 2006, 04:08 AM
#10
Re: Convert TCHAR[][] to char*?
Code:
#define _UNICODE // Enables Unicode character handling for log
#define UNICODE // files using Unicode instead of ANSI encoding.
#include <windows.h>
#include <stdio.h>
#include <tchar.h> // Includes generic text handling functions.
#define MAX_LINE 1026
#define MAX_FIELDS 256
#define MAX_LOGLINES 1000
#define MAX_FIELDLENGTH 1000
// Declare variables.
FILE *pLogFile;
FILE *pLogFile1;
TCHAR ptcLogLine[MAX_LINE];
//char ptcLogLine[MAX_LINE];
TCHAR ptcFieldNames[MAX_FIELDS][MAX_FIELDLENGTH];
TCHAR ptcLogValues[MAX_LOGLINES][MAX_FIELDS][MAX_FIELDLENGTH];
TCHAR *ptcToken;
UINT uiIndex;
UINT uiInput;
UINT uiLineCount = 0;
UINT uiFieldCount = 0;
void main()
{
// Open the log file for parsing.
pLogFile = _tfopen(TEXT("c:\\WMS_20060823.log"), TEXT("r"));
pLogFile1 = _tfopen(TEXT("c:\\write.txt"), TEXT("w+"));
// Read a line at a time from the log file and process it.
while(_fgetts(ptcLogLine, MAX_LINE, pLogFile) != NULL)
{
// Remove the trailing newline character from the log line.
ptcLogLine[_tcsclen(ptcLogLine)-1] = '\0';
// If the field names have been processed,
// then this line can be read in as log data.
if(uiFieldCount > 0)
{
uiIndex = 0;
uiLineCount++;
ptcToken = _tcstok(ptcLogLine, TEXT(" "));
// Store the log data from each field.
while(ptcToken != NULL)
{
uiIndex++;
_tcsncpy(ptcLogValues[uiLineCount - 1][uiIndex - 1],
ptcToken, MAX_FIELDLENGTH);
ptcLogValues[uiLineCount - 1][uiIndex - 1]
[MAX_FIELDLENGTH-1] = '\0';
ptcToken = _tcstok(NULL, TEXT(" "));
}
}
// Process all the field names in the log.
if(_tcsstr(ptcLogLine, TEXT("#Fields:")) != NULL)
{
ptcToken = _tcstok(ptcLogLine, TEXT(" "));
ptcToken = _tcstok(NULL, TEXT(" "));
// Store each field name.
while(ptcToken != NULL)
{
uiFieldCount++;
_tcsncpy(ptcFieldNames[uiFieldCount - 1], ptcToken,
MAX_FIELDLENGTH);
ptcFieldNames[uiFieldCount - 1][MAX_FIELDLENGTH-1] = '\0';
char *temp1;
TCHAR *temp2;
temp1=(char*)&ptcFieldNames;//[0][0];
fprintf(pLogFile1,temp1);
fprintf(pLogFile1,"\n");
temp1="";
ptcToken = _tcstok(NULL, TEXT(" "));
}
}
}
// Close the log file.
fclose(pLogFile);
fclose(pLogFile1);
return;
}
i want to read file from WMS_20060823.log and write to write.txt file. u can use this code only but u can convert the datatype for writing the file.
If I Helped You, "Rate This Post"
Thanks
Guna
-
October 26th, 2010, 11:08 PM
#11
Re: Convert TCHAR[][] to char*?
Yes, it is real pain in the back, especially when you adopting old code with long main function.
The simplest way is to allocate new space for strings and copy characters skipping each second character. Here is the CPP code that duplicates _TCHAR * argv[] to char * argn[].
http://www.wincli.com/?p=72
If you adopting old code to Windows, simple use define mentioned in the code as optional.
int _tmain(int argc, _TCHAR* argv[])
{
char ** argn = allocate_argn(argc, argv);
#define argv argn
// Here is your old code working with arguments
if (argc>1) {
printf(“Arg 1 = ‘%s’\n”, argv[1]); // Just argn intead of argv
}
#undefine argv
release_argn(argc, argn);
return 0;
}
-
October 27th, 2010, 02:58 AM
#12
Re: Convert TCHAR[][] to char*?
 Originally Posted by trasser
Yes, it is real pain in the back, especially when you adopting old code with long main function....
Why do you revive this more than four years old thread?
Only to post a piece of wrong code to it?
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|