seven strings sort

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jmf777
    New Member
    • Aug 2008
    • 19

    seven strings sort

    Hi if your here to help thanks in advance. My problem is I'm writing a code to take seven strings put in by the user sort them alphabetically than print them, but I my compiler is telling me strcmp command is wrong so I cant compile it and I am sure their are other things wrong please help.

    [CODE}

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

    # define N_STRINGS 7

    void swap(char *, char *);

    void strcmp(char *, char *);

    int main (void)
    {
    char w[N_STRINGS];
    char i, j, result;

    scanf("%s", w);
    for (i = 0; i < N_STRINGS; ++i)
    {
    for (j = i + 1; j < N_STRINGS; ++j)
    result = strcmp(w[i], w[j]);
    if( result < 0 )
    swap(&w[i], &w[j]);
    printf ("%s",w[j]);
    }
    return 0;

    }


    void swap(char *p, i *q)
    {
    int tmp;

    tmp = *p;
    *p = *q;
    *q = tmp;
    }

    [/CODE]
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Why r u declaring the the strcmp function in your code when you have included string.h.
    And your strcmp declartaion is wrong as strcmp returns integer and its not void.

    Thanks
    raghu

    Comment

    Working...