#include <stdio.h>#include<string.h>#include<stdlib.h>#defineStr_len_max 100Char**ppcstringarry =NULL;intnum =0;voidOutPutTest1 ();voidOutPutTest2 ();/*string array output function*/voidOutPut () {inti =0 ; for(; i < num; i++) { if(NULL! =Ppcstringarry[i]) { //Free (ppcstringarry[i]);} printf ("index is%d, string is%s.\r\n", I, ppcstringarry[i]); } printf ("\ r \ n"); printf ("%s\r\n","----------------------------------");}/*string array sort output function*/voidSortoutput () {intm =0; intn =0; Char* Temp =NULL; for(M =0; M < num-1; m++) { for(n = m +1; n < num; n++) { if(strcmp (Ppcstringarry[m], ppcstringarry[n]) >0) {Temp=Ppcstringarry[m]; PPCSTRINGARRY[M]=Ppcstringarry[n]; Ppcstringarry[n]=temp; }}} OutPut ();}intMain () {//OutPutTest1 ();OutPutTest2 ();}/*using the Fgets function*/voidOutPutTest1 () {CharAcdate[str_len_max] = {0}; FILE*PFile; PFile= fopen ("F://c/1.txt","ab+"); Num=0; Ppcstringarry= (Char**)malloc(Str_len_max *sizeof(Char*)); while(NULL! =fgets (Acdate, Str_len_max, PFile)) {Ppcstringarry[num]= (Char*)malloc(Str_len_max); memset (Ppcstringarry[num],0, Str_len_max); memcpy (Ppcstringarry[num], acdate, strlen (acdate)+1); memset (Acdate,0,sizeof(acdate)); Num++; } sortoutput ();}/*using the FSCANF function*/voidOutPutTest2 () {//char Acdate[str_len_max] = {0};FILE *PFile; PFile= fopen ("F://c/1.txt","ab+"); intRET =0; Num=0; Ppcstringarry= (Char**)malloc(Str_len_max *sizeof(Char*)); Ppcstringarry[num]= (Char*)malloc(Str_len_max); memset (Ppcstringarry[num],0, Str_len_max); RET= FSCANF (PFile,"%s", Ppcstringarry[num]); while(EOF! =ret) {num++; Ppcstringarry[num]= (Char*)malloc(Str_len_max); memset (Ppcstringarry[num],0, Str_len_max); RET= FSCANF (PFile,"%s", Ppcstringarry[num]); } sortoutput ();}
C based on sort string