Вызов функции в C - PullRequest
       2

Вызов функции в C

2 голосов
/ 26 марта 2011

Вот мой код

#include<stdio.h>

orders_char(int c1, int c2, int c3);

void orders_char(int c1, int c2, int c3)
{

        if(c1 < c2)
                if(c2 < c3)
                        printf("Ordered characters are: %c %c %c", c1, c2, c3);
                else if(c3 < c2 && c1 < c3)
                        printf("Ordered characters are: %c %c %c", c1, c3, c2);
        else if(c2 < c1
                if(c1 < c3)
                        printf("Ordered characters are: %c %c %c", c2, c1, c3);
                else if(c3 < c1 && c3 < c2)
                        printf("Ordered characters are: %c %c %c", c3, c2, c1);
        else if(c1 > c3)
                if (c3 < c2 && c2 > c1)
                        printf("Ordered characters are: %c %c %c", c3, c1, c2);
                else if(c3 > c2 && c2 < c1)
                        printf("Ordered characters are: %c %c %c", c2, c3, c1);


    return;
}

int main(void)
{

        char c1, c2 ,c3;
        int i = 65;

        printf("Please enter 3 capital letters with no spaces: \n");
        scanf("%c%c%c", &c1, &c2, &c3);
        orders_char(c1, c2, c3);
        return 0;
}

Но я получаю ошибки:

8.7.c:3: warning: data definition has no type or storage class
8.7.c:6: error: conflicting types for 'orders_char'
8.7.c:3: error: previous declaration of 'orders_char' was here
8.7.c:6: error: conflicting types for 'orders_char'
8.7.c:3: error: previous declaration of 'orders_char' was here
8.7.c: In function `orders_char':
8.7.c:14: error: syntax error before "if"

Ответы [ 11 ]

0 голосов
/ 26 марта 2011

Вам не нужен orders_char на третьей строке. Это не подходящий прототип (так как тип возвращаемого значения выводится как int), и у вас все равно есть полное определение функции перед main ().

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...