意外令牌附近的语法错误'('使用终端时

时间:2014-08-18 23:57:47

标签: c ubuntu

我正在尝试为我的平板电脑获得一个cpuid,我有这个代码,当我通过终端在ubuntu上执行它时,它会出现以下错误: 第5行:意外令牌附近的语法错误'(' 第5行:' int main(无效)'

我该如何解决这个问题?

#include <libusb-1.0/libusb.h>
#include <stdio.h>
#include <stdint.h>

int main(void)
{
    unsigned char data[64];
    int received_length;
    int r = 1;
    libusb_context* ctx = NULL;
    libusb_device_handle* dev_handle = NULL;

    libusb_init(&ctx);
    dev_handle = libusb_open_device_with_vid_pid(ctx, 0x0955, 0x7820);
    if(dev_handle)
    {
        r = libusb_bulk_transfer(dev_handle, 0x81, data, sizeof(data), &received_length, 10000);
        if (r == 0)
        {
            if(received_length == 8)
            {
               printf("uid: 0x%08X%08X\n", *((uint32_t*)data+1), *((uint32_t*)data+0));
            }
            else
            {
                r = 1;
                printf("Error: We got %d bytes of data insetad of the 8 bytes we expected...\n", received_length);
            }
        }
        else
        {
            printf("Error: USB read failed!\n");
        }
        libusb_release_interface(dev_handle, 0);
    }
    else
    {
        printf("Error: Failed to open device!\n");
    }
    libusb_exit(ctx);
    return r;
}

1 个答案:

答案 0 :(得分:4)

您需要编译程序并运行可执行文件。如果程序在foo.c中,则使用以下代码编译它:

gcc foo.c -o foo

然后用:

执行它
./foo

您无法直接运行C源文件 - C不是脚本语言。