首页 > > 详细

讲解UoG-UESTC程序、辅导Structures编程、c/c++设计编程辅导讲解留学生Processing|讲解Database

UoG-UESTC 2020 Page 1 of 9
Lab Session: Strings, Structures and Bit Manipulation
Exercise 1: Strings are Arrays of Characters
Background
You may recall that in Lab 1, we defined strings variables as:
char animal[100] = "cat";
As you may guess now, we were actually creating an array of characters.
You may have noticed that we can print out a string without needing to specify the total
number of characters:
char animal[100] = "ferocious kitten";
printf("The %s sleeps!", animal);
The above code will print out "The ferocious kitten sleeps", even though the
char array animal contains 100 chars. This is because the final character is a special
ascii-null character: '\0' (added automatically by the compiler in this case)
Technical details
Dealing with strings:
#include
#include // extra include!
int main() {
char animal[100] = "ferocious kitten";
// length of the string
int length = strlen(animal);
int i;
for (i=0; i

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!