Thread: need help with <tchar.h>

  1. #1
    Registered User
    Join Date
    Dec 2010
    Location
    Lucknow, India
    Posts
    72

    Wink need help with <tchar.h>

    please answer me in C programming not in C++

    how to take input in a TCHAR sting at run time..???
    Suppose an example of Simple string..
    char str[43];
    gets(str); //here gets() tke the input at run time and send it to the char String.
    now please tell me.. if we declare..
    TCHAR str[45];
    now, how to take input in this string at run time..???
    and
    how to add two TCHAR strings..??? as we did by using strcat() in case of CHAR string..
    PLEASE HELP ME..

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    First of all, you should NEVER EVER use gets()
    SourceForge.net: Gets - cpwiki

    Second, if you're using TCHAR and a Microsoft platform, you should read this
    Using Generic-Text Mappings (CRT)

    So for example, _fgetts maps to fgets() when TCHAR is a char, and fgetws() when TCHAR is a wide character.
    Code:
    TCHAR str[45];
    _fgetts( str, sizeof(str), stdin );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by Salem View Post
    _fgetts( str, sizeof(str), stdin );
    Almost:
    _fgetts( str, sizeof(str) / sizeof(*str), stdin );

    The buffer size is in characters, not bytes.

  4. #4
    Registered User
    Join Date
    Dec 2010
    Location
    Lucknow, India
    Posts
    72
    thanks guys..

    Please tell me how to add two TCHAR strings..
    lets an Example,
    TCHAR str1[]=_T("Hello");
    TCHAR str2[]=_T("World");

    now i want to add these these two strings in a Single one.
    Suppose when I print str1[] only i get the Output as "Hello World"...
    please help me Out..
    Compiler: Borland C, OS: windows xp.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Look for the TCHAR version of strcat. It's probably strcat with an extra t somewhere, and maybe an underscore at the front.

    Be aware: you will have to make sure you have enough room in your result string for the entire result. As you have it now, neither str1 nor str2 will be long enough.

  6. #6
    Registered User
    Join Date
    Dec 2010
    Location
    Lucknow, India
    Posts
    72
    here to add two TCHAR strings Im using _tcscat()
    but there is a problem when I take one string Input at run time..
    here is the code
    Code:
    void main()
    { TCHAR A[50];
    TCHAR B[20]=_T("World");
    _fgetts( A, sizeof(A), stdin);   //Here I give input "Hello" in the String A.
    _tcscat(A,B);
    _putts(A);
    getch();
    }
    here the output is: Hello
    World

    and want it as: Hello World

    HELLPPPP..

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Then strip off the newline before adding world to the end.

  8. #8
    Registered User
    Join Date
    Dec 2010
    Location
    Lucknow, India
    Posts
    72
    Actually i want to store the complete text in a Single string.
    i think the command of new line is also get added with the string A.
    please tell me how to remove it from the String.

  9. #9

  10. #10
    Registered User
    Join Date
    Dec 2010
    Location
    Lucknow, India
    Posts
    72
    My problem is Solved. Thank You So Much Guys...
    Keep this good work on.
    thanks "adeyblue" and A Big THANKS to "SALEM & tabstop"
    thanks a Lot. ^ - ^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. <tchar.h> vs. <winnt.h>
    By homeyg in forum Windows Programming
    Replies: 1
    Last Post: 02-06-2006, 06:57 PM