首页 > > 详细

Structures编程辅导、讲解c/c++程序语言、辅导program程序解析Java程序|讲解R语言程序

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 微信:codinghelp
程序辅导网!