吴裕雄--天生自然C语言开发:字符串

char greeting[6] = {‘H‘, ‘e‘, ‘l‘, ‘l‘, ‘o‘, ‘\0‘};
char greeting[] = "Hello";
#include <stdio.h>

int main ()
{
   char greeting[6] = {‘H‘, ‘e‘, ‘l‘, ‘l‘, ‘o‘, ‘\0‘};

   printf("Greeting message: %s\n", greeting );

   return 0;
}
#include <stdio.h>
#include <string.h>

int main ()
{
   char str1[12] = "Hello";
   char str2[12] = "World";
   char str3[12];
   int  len ;

   /* 复制 str1 到 str3 */
   strcpy(str3, str1);
   printf("strcpy( str3, str1) :  %s\n", str3 );

   /* 连接 str1 和 str2 */
   strcat( str1, str2);
   printf("strcat( str1, str2):   %s\n", str1 );

   /* 连接后,str1 的总长度 */
   len = strlen(str1);
   printf("strlen(str1) :  %d\n", len );

   return 0;
}

原文地址:https://www.cnblogs.com/tszr/p/10968577.html

时间: 2024-08-30 16:38:49

吴裕雄--天生自然C语言开发:字符串的相关文章

吴裕雄--天生自然C语言开发:结构体

struct tag { member-list member-list member-list ... } variable-list ; struct Books { char title[50]; char author[50]; char subject[100]; int book_id; } book; //此声明声明了拥有3个成员的结构体,分别为整型的a,字符型的b和双精度的c //同时又声明了结构体变量s1 //这个结构体并没有标明其标签 struct { int a; char

吴裕雄--天生自然 R语言开发学习:图形初阶(续一)

# ----------------------------------------------------# # R in Action (2nd ed): Chapter 3 # # Getting started with graphs # # requires that the Hmisc and RColorBrewer packages # # have been installed # # install.packages(c("Hmisc", "RColorB

吴裕雄--天生自然 R语言开发学习:基本图形

#---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 # # Basic graphs # # requires packages vcd, plotrix, sm, vioplot to be installed # # install.packages(c("vcd", "plotrix", "sm"

吴裕雄--天生自然 R语言开发学习:基本图形(续二)

#---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 # # Basic graphs # # requires packages vcd, plotrix, sm, vioplot to be installed # # install.packages(c("vcd", "plotrix", "sm"

吴裕雄--天生自然 R语言开发学习:高级数据管理(续三)

#-----------------------------------# # R in Action (2nd ed): Chapter 5 # # Advanced data management # # requires that the reshape2 # # package has been installed # # install.packages("reshape2") # #-----------------------------------# # Class R

吴裕雄--天生自然 R语言开发学习:基本图形(续一)

#---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 # # Basic graphs # # requires packages vcd, plotrix, sm, vioplot to be installed # # install.packages(c("vcd", "plotrix", "sm"

吴裕雄--天生自然 R语言开发学习:高级数据管理

#-----------------------------------# # R in Action (2nd ed): Chapter 5 # # Advanced data management # # requires that the reshape2 # # package has been installed # # install.packages("reshape2") # #-----------------------------------# # Class R

吴裕雄--天生自然 R语言开发学习:功效分析

#----------------------------------------# # R in Action (2nd ed): Chapter 10 # # Power analysis # # requires packages pwr to be installed # # install.packages("pwr") # #----------------------------------------# par(ask=TRUE) library(pwr) # t te

吴裕雄--天生自然 R语言开发学习:功效分析(续一)

#----------------------------------------# # R in Action (2nd ed): Chapter 10 # # Power analysis # # requires packages pwr to be installed # # install.packages("pwr") # #----------------------------------------# par(ask=TRUE) library(pwr) # t te