Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is wcscat in C?

Faraz Karim

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

wcscat is a function defined in thewchar.h header file. wscat serves to concatenate and store a pointed wchar_t (wide strings) and a constant wchar_t takes it as inputs.

Function syntax

Following is the syntax for the wcscat function:

Parameters

The wcscat function takes in a wide string pointer and a constant wide string as inputs:

  • dst: The pointer to a wide string is also used to store the final concatenated string. The wide string pointer to this pointer must have enough size to accommodate the concatenated string.

  • src: The constant wide string to be appended. src is appended to the string pointed by dst

Return value

wscat returns the dst pointer after appending the src wide string to it.

Example

The following is a very simple example of using the wcscat to concatenate two wide strings. We create a wide strings pointer and use the wcscat function to append a constant wide string and store it into the wstr array. Then, we use the special wide print function wprintf to print out the concatenated string.

It is to be noted that wide strings are slightly different from normal strings. They differ in the sense that they require you to put an ‘L’ before the intended initialization value. During printing, wide strings are represented by %ls instead of the conventional %s for normal strings.

#include <wchar.h>
int main ()
{
// decaring and initializing a wide strings
wchar_t wstr[80] = L"Educative has";
// concatenating the two wide strings
wcscat (wstr,L" a ton of courses");
// printing the destination array
wprintf (L"%ls\n",wstr);
return 0;
}

RELATED TAGS

c

CONTRIBUTOR

Faraz Karim
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring