Compiler reports code error

-1

I'm new to C language.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char card_name[3];
    int count = 0;

    while(card_name[0] != 'X')
    {
        puts("Enter the card_name: ");
        scanf("%2s", card_name);
        int val = 0;

        switch(card_name[0])
        {
            case 'K':
            case 'Q':
            case 'J':
                val = 10;
                break;
            case 'A':
                val = 11;
                break;
            case 'X':
            default:
                val = atoi(card_name);
                if((val < 1) || (val > 10))
                {
                    puts("I don't undstand that value");
                    continue;
                }
        }

        if((val > 2) && (val < 7))
        {
            count++;
        }
        else if(val == 10)
        {
            count--;
        }

        printf("Current count : %i\n", count);
    }

    return 0;
}

When I try to run the code it returns me an error:

root@kali:~# gcc test.c -o test
root@kali:~# ./test.c
./test.c: line 3: erro de sintaxe próximo do 'token' não esperado '('
./test.c: line 3: 'int main() {'
    
asked by anonymous 06.11.2014 / 23:52

1 answer

3

The compiler gcc read its source code test.c and generated an executable file named test (without .c ). But instead of calling this executable ( ./test ) you're calling the source code ( ./test.c ). Call ./test that will work.

    
07.11.2014 / 00:03