I am a Java programmer who has C this semester. Needless to say, my writing style is heavily influenced by Java, which is probably not a great thing. I'd be grateful for a few nudges in the right direction. Here's the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 100
#define WID 80
void sort(char s[][WID], int n);
void display(char s[][WID], int n);
int main()
{
int n, i;
char s[LEN][WID];
printf("Enter number of strings : ");
scanf("%d", &n);
printf("Enter strings one by one :\n");
for (i = 0; i < n; i++) {
printf("%d : ", i + 1);
scanf(" %s", s[i]);
}
printf("The initial elements are:\n");
display(s, n);
sort(s, n);
printf("The elements after sorting are:\n");
display(s, n);
return 0;
}
void sort(char s[][WID], int n)
{
int i, item;
char elem[WID];
for (item = 1; item < n; item++) {
strcpy(elem, s[item]);
for (i = item; strcmpi(s[i - 1], elem) > 0 && i > 0; i--) {
//strcpy(s[i], s[i - 1]);
}
memcpy(&s[i + 1], &s[i], (item - i) * WID);
strcpy(s[i], elem);
}
}
void display(char s[][WID], int n)
{
int i;
printf("\n\n");
for (i = 0; i < n; i++) {
printf("%s ", s[i]);
}
printf("\n\n");
}
If you see something blasphemous, don't hesitate to call it out.