C language-pointer and pointer arrays to multidimensional arrays

Source: Internet
Author: User
Tags strcmp

#include <stdio.h>//void Show (char *p[]);voidShowChars[][Ten]);intMain () {Chars[3][Ten]={"123","ABC","XYZ"}; Char*p[Ten]; //array of pointers to iterate overp[1] = s[1]; Char(*PS)        []; PS=s;}

#include <stdio.h>#include<string.h>#defineSIZE 80#defineLMT 3#defineHALT ""/** * String sort function function prototype declaration*///if a two-dimensional array is passed directly, only the array elements can be displayed inside the function, and the element position cannot be changedvoidStr_sort (CharStr[][size],intnum);//void Str_sort (char *str,int num);intMain () {CharInput[lmt][size]; //array of pointers, to assign values to each element individually, pointers to multidimensional arrays only need to assign values to pointer variables//to specify the size of the array when the pointer array is initialized, a pointer to a multidimensional array allocates only the memory space of the pointer variable        Char*PS[LMT]; intCT =0; intK;  while(CT&LT;LMT && gets (input[ct])! = NULL && input[ct][0] !=' /') {PS[CT]=INPUT[CT]; CT++; }        //Str_sort (PS,CT);Str_sort (INPUT,CT); //puts ("Here is the Res list:"); //For (k=0;k<ct;k++) {//puts (ps[k]); //}        return 0;}voidStr_sort (CharStr[][size],intnum) {        //Char *tmp; //int Top,seek; //For (top=0;top<num-1;top++) {//For (seek=top+1;seek<num;seek++) {//if (strcmp (Str[top], Str[seek]) > 0) {//tmp = Str[top]; //Str[top] = Str[seek]; //Str[seek] = tmp; //              }        //      }        //}        inti; str[1][1]='*';  for(i=0; i<num;i++) {printf ("%s\n", Str[i]); }}

#include <stdio.h>#include<string.h>#defineSIZE 80#defineLMT 3#defineHALT ""/** * String sort function function prototype declaration*/voidStr_sort (Char*str[],intnum);intMain () {CharInput[lmt][size]; Char*PS[LMT]; intCT =0; intK;  while(CT&LT;LMT && gets (input[ct])! = NULL && input[ct][0] !=' /') {PS[CT]=INPUT[CT]; CT++;        } str_sort (PS,CT); Puts ("Here is the res list:");  for(k=0; k<ct;k++) {puts (ps[k]); }        return 0;}voidStr_sort (Char*str[],intnum) {        Char*tmp; intTop,seek;  for(top=0; top<num-1; top++){                 for(seek=top+1; seek<num;seek++){                        if(strcmp (Str[top], Str[seek]) >0) {tmp=Str[top]; Str[top]=Str[seek]; Str[seek]=tmp; }                }        }}

C language-pointer and pointer arrays to multidimensional arrays

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.