Explanation for working of (char *) type syntax

This is a discussion on Explanation for working of (char *) type syntax within the C Programming forums, part of the General Programming Boards category; It feel bad but I got stuck with a noobish type syntax, need explanation. Code: LPARAM name; //have a pre ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    29

    Explanation for working of (char *) type syntax

    It feel bad but I got stuck with a noobish type syntax, need explanation.

    Code:
    LPARAM name; //have a pre defined value
    LPARAM length; //have a pre defined value
    fgetws((wchar_t *)name,length,stdin); //need explanation
    wchar_t *ptr=wcspbrk((wchar_t *)name,L"\r\n"); //explanation
    Its actually the part of a another large code. here 'name' and 'length' will get values at the time of calling. So don't worry about their values.
    Do explain how this small code works here.

    And how to send another value to 'name' as it is given by fgetws().???

    Thanks in advance.

  2. #2
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    LPARAM is a pointer.

    "name" is of type LPARAM.

    "(wchar_t *) name" casts name to a pointer to a (wide, i.e. Unicode) string.

    The fgetws gets a wide string of length "length", from stdin, and put it into that string.

    You can do the last line on your own now if I tell you that "\r\n" is a carriage-return and line-feed and you can lookup wcspbrk online.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    29
    Quote Originally Posted by ledow View Post
    LPARAM is a pointer.

    "name" is of type LPARAM.

    "(wchar_t *) name" casts name to a pointer to a (wide, i.e. Unicode) string.

    The fgetws gets a wide string of length "length", from stdin, and put it into that string.

    You can do the last line on your own now if I tell you that "\r\n" is a carriage-return and line-feed and you can lookup wcspbrk online.
    Well in that case...
    Are the two below lines results into similar output.??
    Code:
    fgetws((wchar_t *)name,length,stdin); //with input of 123
    and
    Code:
    (wchar_t *)name=L"123";
    If not.. then how to pass the value "123" to the (wchar_t *)name through code(manually instead of keyboard) which results to similar output as it is done by fgetws() function.???

    and Thanks for your explanation. It is crystal clear.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,607
    Code:
    wcscpy((wchar_t*)name, L"123);
    gg

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    29
    Quote Originally Posted by Codeplug View Post
    Code:
    wcscpy((wchar_t*)name, L"123);
    gg
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 07-24-2012, 10:41 AM
  2. Replies: 2
    Last Post: 11-23-2011, 11:30 AM
  3. Replies: 6
    Last Post: 05-16-2011, 05:12 AM
  4. the correct syntax for ''char'' type
    By benasp in forum C Programming
    Replies: 1
    Last Post: 02-21-2005, 04:39 PM
  5. strcpy syntax explanation needed
    By blight2c in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2002, 07:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21