I'm new to C programming and I am currently trying to alphabetize a list of words. As of now I have a working program (posted below), however I am trying to run it on a microprocessor that does not allow the use of scanf() or fgets(). I was wondering if there is a way around this by using getchar() and putchar() but still use the same logic to alphabetize the list.
Code:
#include<stdio.h>
#include<string.h>
void main() {
int i, j, n;
char s[10][20], t[20];
scanf("%d",&n); //reads user input
for (i = 0; i <= n; i++)
fgets(s[i],20,stdin);
for (i = 1; i < n; i++) { //sort through and compare words
for (j = 1; j < n; j++) {
if (strcmp(s[j - 1], s[j]) > 0) {
strcpy(t, s[j - 1]);
strcpy(s[j - 1], s[j]);
strcpy(s[j], t);
}
}
}
printf("\nSorted List"); //print sorted words
for (i = 0; i <= n; i++)
printf("%s", s[i]);
}