strncpy ในภาษา C, C++

6 Sep 2015,
Share: 

strncpy เป็น function สําหรับ copy string จากตัวแปรต้นทางไปใส่ในตัวแปรปลายทาง

รูปแบบการใช้

char *strncpy(char *dest, const char *src, size_t n)

 Parameter

  • dest —String ปลายทาง
  • src —String ต้นทาง
  • n —จํานวนตัวอักษรของต้นทางที่ต้องการ copy

Example

#include <stdio.h>
#include <string.h>

int main()
{
 char src[] = "This is thitiBlog.com";
 char dest[50];

 memset(dest, '\0', sizeof(dest));
 strncpy(dest, src, 10);

 printf("Final copied string : %s\n", dest);

 return(0);
}

Output:

Final copied string : This is th

Suggestion blogs

คํานวณความต้านทาน วงจรขนาน

การคํานวณค่าความต้านทานรวม เมื่อนํา R(ตัวต้านทาน) มาต่อกัน แบบขนาน ดังรูป

Review ไฟฉาย JetBeam IIM

ไฟฉาย JetBeam รุ่น IIM เป็นไฟฉายรุ่นที่มีความสว่างสูงสุด 1,100 Lumens แสงพุ่งไกลถึง 230 เมตร จุดเด่นคือ สามารถล็อค switch ปิด-เปิด ได้เพื่อป้องกันไม่ให้เปิดไฟฉายโดยบังเอิญ

Vue.js เริ่มต้น ตอน5 (ทําความรู้จักกับ Props)

หลังจากที่เราเรียนรู้ Component กันไปแล้ว ถ้ายังจํากันได้ภายใน Component มี Option ตัวนึงชื่อว่า Props ซึ่งมีหน้าที่ รับข้อมูลจากภายนอก Component เข้ามาใช้งานภายใน Component โดยจะรับข้อมูลผ่านทาง Attribute การใช้งาน Props สามารถใช้งานได้หลายรูปแบบ เราจะมาเรียนรู้ไปทีละแบบนะครับ


Copyright © 2019 - 2026 thiti.dev | v1.61.0 | Privacy policy | 

Build with ❤️ and Astro.

Github profile Linkedin profile Instagram X profile Nostr Youtube channel Telegram Email contact วงแหวนเว็บ