I'm making a program that if a user enters a word (and that's maximum length is 20), then prints the word in alphabetical order.
This code below is that I wrote.
#include <stdio.h>
#include <string.h>
#pragma warning (disable:4996)
#define MAX 20
void bubble_sort(char* arr, int n);
int main(void) {
char words[MAX];
int n = sizeof(words) / sizeof(char);
scanf("%s", words);
bubble_sort(words, n);
printf("%s", words);
return 0;
}
void bubble_sort(char* arr, int n) {
int i, j, tmp = 0;
for (i = 0; i < n - 1; i++) {
for(j=0;j<i-1;j++)
if (*(arr+j) > *(arr+j+1)) {
tmp = *(arr+j);
*(arr+j) = *(arr+j+1);
*(arr+j+1) = tmp;
}
}
}
But it doesn't work. I used bubble sorting. I am not skilled to use pointer arrays and sorting, so I can't catch what's wrong.
I'm working on Visual Studio 2019, and it says that return value ignored scanf(). I can't understand. What's wrong?