C Language Basics 5

Source: Internet
Author: User
Tags first string

Definition of a two-dimensional array:

Data type array name [constant expression 1] [constant expression 2] = {...}

int a[2][3] ={

{4,5,6},

{7,8,0}//or {7} does not write after 8 and 9, the system will help you add 0{7,0,0} by default

};

OR:

int b[3][2] ={3,87,43,66,82,11,34};

OR:

int b[][2] ={3,87,43,66,82,11,34}; Horizontal can not write

Array of strings

char array name [number of strings] [maximum allowable value per string] ={....}

Char str[3][15] ={"ipad", "ipod", "iphone"};

A string array is essentially a two-dimensional array that accesses a string using the array name [first-dimensional subscript].

The length of each string cannot exceed the length of the second dimension-1.

For example:

Char str2[3][20] ={"Luoshuailuotingluomama", "ipod", "ipad"};

The second dimension is 20, 20-1 = 19, but the first string is more than 19.

Char str2[3][20] ={"luoshuailuotingluomamadddddddssssssss", "ipod", "ipad"}; will not error, but will be warned.

for (int i =0; i < 3; i++) {

printf ("The End of Result:%s\n", Str2[i]);

}

Consider a question:

Creates an array of strings, pairs of strings (English?) Sort from small to large

Char str[5][15] ={"ipad", "ipod", "iphone", "main", "Luoshuai"};

Char temp[] ={0};

for (int i =0; i < strlen (str); i++) {

for (Int J =0; J<strlen (str)-i-1;j++) {

     if (strcmp (Str[j] > str[j+1]) > 0) {

Strcopy (Temp,str[j]);

Strcopy (str[j],str[j+1]);

Strcopy (str[j+1],temp);

}

}

}

for (Int J =0; J<strlen (str); j + +) {

printf ("The End of Result:%s\n", str[j]);

}

C Language Basics 5

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.