#include <stdio.h>
#include <string.h>
#include <cs50.h>
#include <string.h>
void swaps(char*s,char*t)
{
char*a = t;
strcpy(t,s);
strcpy(s,a);
}
int main(void)
{
int n=GetInt();
char* a[n];
int c=0;
for(int i=0;i<n;i++)
{
a[i]=GetString();
}
puts("");
for(int j=0;j<n;j++)
{
for(int i=0;i<n-1;i++)
{
c=strcmp(a[i],a[i+1]);
if(c>0)
{
swaps(a[i],a[i+1]);
}
}
}
for(int i=0;i<n;i++)
{
printf("%s\n",a[i]);
}
return 0;
}
I am trying to arrange strings in alphabetic order using pointers.I was able to get desired output using 2d char arrays but not able to get the correct output using pointers.