文字列のソート
Posted: 2016年8月19日(金) 17:32
				
				プログラムの引数として適当な個数(3個以上100個以下)の文字列を与えて、それらを辞書順にソートするプログラムを作りたいのですが、strcmpの使い方がよくわかりません。どなたかご享受ください。
			#include <stdio.h>
#include <string.h>
void compare_string(const char *p, const char *q)
{
    int n = strcmp(p, q);
    printf("%sは%s%s\n", p, q, n < 0 ? "より小さい" : n == 0 ? "と同じ" : "より大きい");
}
int main(void)
{
    char *s[] = { "abc", "AB", "abC", "AB", "ab", "AbC", "abC" };
    int i, j, n = sizeof(s) / sizeof(s[0]);
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            compare_string(s[i], s[j]);
        }
    }
    return 0;
}