mardi 2 juin 2020

What is the problem with this lvalue error in ascending array?

#include <stdio.h>
#include <string.h>

int main(void)
{
    char names[10][20] = { "kim", "lee", "sin", "jo", "kim2", "chae", "jin", "bak", "so", "choi" };

    int i, j;
    char tmp[20];

    printf("\nfirst\n");
    for (j = 0; j < 10; j++)
        printf("%5s", names[j]);
    printf("\n");

    for (i = 0; i < 9; i++)
        for (j = 0; j < 9 - i; j++)
            if (strcmp(names[j], names[j + 1]) > 0)
            {
                //tmp = names[j];//
                //names[j] = names[j + 1];//
                //names[j + 1] = tmp;//
                //break;//
//This part.//
            }



    printf("\nSorted Result\n");
    for (j = 0; j < 10; j++)
        printf("%5s", names[j]);
    printf("\n");

    return 0;
}

I have to make this code without strcpy. but this code has l-value error. Any hints or suggestions to this problem?

Aucun commentaire:

Enregistrer un commentaire