hi everyone,
i was writing an application, with the c language, which asks the user to give the number of strings to sort, and then sort'em, but i had some problems that i can't figure out, would u please help me
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void getting(char *words[], int num);
void sort(char *words[], int n);
int i=0;
int main(int argc, char *argv[])
{
char (*word)[30]=NULL;
int n=0;
getting(word, n);
sort(word, n);
system("pause");
return EXIT_SUCCESS;
}
void getting(char *words[], int num)
{
printf("how many words u wanna sort\t");
scanf("%ld", &num);
getchar();
words=(char *)calloc(num, sizeof(char));
for(i=0; i<num; i++)
{
printf("enter the %ldth word : ", i);
fgets(&words[i], 30, stdin);
}
}
void sort(char *words[], int n)
{
int k=1, sorted=1;
char tmp[30];
do
{
sorted=1;
for(i=0; i<n-k; i++)
{
if(strcmp(words[i], words[i+1])>0)
{
strcpy(tmp, words[i]);
strcpy(words[i], words[i+1]);
strcpy(words[i+1], tmp);
sorted=0;
}
}
k++;
}
while(sorted!=1);
for(i=0; i<n; i++)
printf("%s\n", words[i]);
}