Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- char **pp_sz;
- char* genword();
- void gennewpntrs();
- void stringsprint();
- void sort(char **);
- void sortprint();
- ////////////////////////////////////////////////////////////////////
- int main() //
- {
- pp_sz = (char**)malloc(40);
- char sz [99] = "SONY",
- sz2[99] = "Pictures";
- pp_sz[ 0] = (char*)sz;
- pp_sz[ 1] = (char*)sz2;
- pp_sz[2] = (char*)malloc(99);
- strcpy(pp_sz[2], "TDK");
- srand(time(0));
- gennewpntrs();
- stringsprint();
- sort(pp_sz);
- stringsprint();
- }
- ////////////////////////////////////////////////////////////////////
- char* genword()
- {
- int n = 1 + rand()%8;
- char A = 65 + rand()%26;
- static char sz[99];
- int i = 0;
- for(; i <= n; i++)
- {
- if(i == 0) sz[i] = 65 + rand()%26;
- else sz[i] = 97 + rand()%26;
- }
- printf("i = %d\n", i);
- sz[i] = 0;
- return sz;
- }
- ////////////////////////////////////////////////////////////////////
- void gennewpntrs()
- {
- for(int g = 3; g <= 10; g++)
- {
- pp_sz[g] = (char*)malloc(99);
- strcpy(pp_sz[g], genword() );
- }
- }
- ////////////////////////////////////////////////////////////////////
- void stringsprint()
- {
- for(int i = 0; i <= 10; i++)
- {
- printf("pp_sz[%2d] = %s\n", i, pp_sz[i]);
- }
- printf("\n");
- }
- ///////////////////////////////////////////////////////////////////
- void sort( char **p_sz)
- {
- int i = 0,
- n = 0,
- nFlag = 0;
- char *swap;
- do{ nFlag = 0;
- for(i = 0; i < 10; i++)
- {
- if(*pp_sz[i] > *pp_sz[i+1])
- {
- nFlag = 1;
- swap = pp_sz[i] ;
- pp_sz[i] = pp_sz[i+1];
- pp_sz[i+1] = swap;
- }
- }
- }
- while(nFlag > 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement