Nov 29, 2010 at 3:46pm UTC
Thanks for replying first of all.
I tried with TCHAR and also with WCHAR and i still get the compiler error.
I have to say that i the UNICODE is defined in my program so i need the TEXT macro in order to convert the string to UNICODE format.
So any other ideas.
Last edited on Nov 29, 2010 at 3:55pm UTC
Nov 29, 2010 at 4:33pm UTC
I've just spent about five minutes searching for scan_f. What is that? I can find no references to it. Or do you mean scanf?
Nov 29, 2010 at 6:18pm UTC
just replace the char with WCHAR or
WCHAR str[100];
dosomething(TEXT(str));
TCHAR str[100];
dosomething(TEXT(str));
as for the scan_f it's a typing error ,i wanted to type scanf()
Nov 29, 2010 at 7:05pm UTC
This works for me...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
//console program - main.cpp
#include <tchar.h>
#include <stdio.h>
void DoSomething(TCHAR* szBuffer)
{
_tprintf(_T("%s" ),szBuffer);
}
int main()
{
TCHAR szText[]=_T("Hello, World!\n" );
DoSomething(szText);
getchar();
return 0;
}
/* --Output--
Hello, World!
*/
...which is exactly what kbw said to do in his 1st reply.
Last edited on Nov 29, 2010 at 7:08pm UTC
Nov 29, 2010 at 7:38pm UTC
yes that might works but how can i get a string from the user, not just printing a predefined string on the screen.
That is what i can't figure out.
Nov 29, 2010 at 8:42pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
//console program - main.cpp
#include <tchar.h>
#include <stdio.h>
void DoSomething(TCHAR* szBuffer)
{
_tprintf(_T("%s" ),szBuffer);
}
int main()
{
TCHAR szText[128];
_tscanf(_T("%s" ),szText); //I entered freddie [ENTER]
DoSomething(szText);
getchar();
return 0;
}
/* --Output--
Compiling: main.cpp
Linking console executable: Uni2.exe
Output size is 6.00 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
Run:
freddie
freddie
Process returned 0 (0x0) execution time : 4.595 s
Press any key to continue.
*/
Last edited on Nov 29, 2010 at 8:44pm UTC
Nov 30, 2010 at 10:21am UTC
I repeat, the TEXT and _T macros convert your string literal ...
In DoSomething(_T(szText));
szText is not a literal, it's a variable.
It should be DoSomething(szText);
It may be helpful if you look up the definition of _T
Last edited on Nov 30, 2010 at 11:42am UTC
Nov 30, 2010 at 3:30pm UTC
All the _T or TEXT macros do is prepend a L to whatever symbol they enclose if UNICODE is defined. If it isn't defined they don't do anything. That is why if you put your str variable with the macro it gets converted to Lstr by the preprocessor, and you get a variable not declared error message. You seem determined to put string variables within these macros and it won't work as kbw says.