typedefs have a purpose, if they didn't and they were bad, they would be removed from the standard.
who would want to type
char*** cptrptrptr;
many times for each one you define?
it's easier to just
typedef char*** char2;
char2 cptrptrptr;
and it helps you avoid some confusion.
in my opinion, #define is VERY BAD to use for that instance.
and another thing, I only used typedef because I was messing around trying to figure out how I could get it to work.
now it crashes with an access violation (out of bounds I guess)
the new code (LOL):
Code:
#include <stdio.h>
#include <string.h>
typedef char** char1;
typedef char1 *cptr;
void str_swap(char** str1, char** str2);
void bubble_sort(cptr array,int length)
{
int i, j,s;
bool flag = 1;
char* tmp;
int arrayLength = length;
for(i = 0; (i < arrayLength) && flag; i++)
{
flag = 0;
for (j=0; j < (arrayLength -1); j++)
{
s = strcmp(*array[j+1],*array[j]);
if(s>0)//string 2 is greater
{
str_swap(array[j+1],array[j]);
}
}
}
}
int main()
{
char* str1= "Alfred";
char* str2 = "Albert";
char* strs[] = {str1,str2,"Linux","Penguin","Lorraine","Lucas"};
int len = 6;
for(int j=0;j<len;j++)
printf("%s ",strs[j]);
printf("\n");
bubble_sort((cptr)&strs,len);
for(j=0;j<len;j++)
printf("%s ",strs[j]);
printf("\n");
return 0;
}
void str_swap(char** str1, char** str2)
{
char* tmp;
tmp = *str1;
*str1 = *str2;
*str2=tmp;
}
any ideas?
-LC