hhhhhhhaa 发表于 2018-9-5 10:13:57

main.c(20): error: #8: missing closing quote 出现这个错误是怎么回...

main.c(20): error:#8: missing closing quote 出现这个错误是怎么回事啊?



本来应该发送的是                        char sText = { "多字节字符串!OK!" };
结果在编译的时候 报错了            char sText = { "澶氬瓧鑺傚瓧绗︿覆锛丱K锛?" };
怎么会出现这种情况啊



feixiang20 发表于 2018-9-5 23:33:59

出现乱码是因为添加字符的操作有问题

toofree 发表于 2018-9-5 10:18:45

本帖最后由 toofree 于 2018-9-5 10:22 编辑

好歹发个工程呀,谁知道你用的什么IDE,什么编辑器,什么编码方式?
除了字符串本身外,有没有用中文输入法时输入过标点符号?
提示引号附近有错,那就肯定有错。

你确定你这是用的C语言吗?没这么定义的,又带花括号,又带引号的,这不是printf。

char sText = "多字节字符串!OK!";

发表于 2018-9-5 10:20:02

估计还是编译器环境的配置问题。

hhhhhhhaa 发表于 2018-9-5 10:31:37

toofree 发表于 2018-9-5 10:18
好歹发个工程呀,谁知道你用的什么IDE,什么编辑器,什么编码方式?
除了字符串本身外,有没有用中文输入法 ...

# include "main.h"

int a=0xC4E3BAC3;
u8 b[]={"你好"};

int main(void)
{

       
                        delay_init();                           
                        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
                        My_USART2_Init();
       
   
       
              while(1)
              {
            
            
            
            
            
            
            
            
            
            
            
            
            
                                                               
                                                printf("%s",b);
//               
//                                               
                  delay_ms(10000);   
                          delay_ms(10000);
            delay_ms(10000);
//            delay_ms(10000);
//            delay_ms(10000);                       
//            printf("%x",a);
//                                        delay_ms(10000);   
                }
               
       
}


这是主函数的代码

#include "sys.h"
#include "usart.h"          

#if SYSTEM_SUPPORT_OS
#include "includes.h"                                        //ucos 使用          
#endif


//////////////////////////////////////////////////////////////////
//加入以下代码,支持printf函数,而不需要选择use MicroLIB          
#if 1
#pragma import(__use_no_semihosting)            
            
struct __FILE
{
        int handle;

};

FILE __stdout;      
//定义_sys_exit()以避免使用半主机模式   
intsys_exit(int x)
{
        x = x;
        return x;
}
//重定义fputc函数
int fputc(int ch, FILE *f)
{      
        while((USART2->SR&0X40)==0);//循环发送,直到发送完毕   
    USART2->DR = (u8) ch;      
        return ch;
}
#endif


void My_USART2_Init(void)
{

       
        GPIO_InitTypeDef GPIO_InitStrue;
        USART_InitTypeDef USART_InitStrue;
        NVIC_InitTypeDef NVIC_InitStrue;
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
       
        GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP;
        GPIO_InitStrue.GPIO_Pin=GPIO_Pin_2;
        GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&GPIO_InitStrue);
       
        GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IN_FLOATING;
        GPIO_InitStrue.GPIO_Pin=GPIO_Pin_3;
        GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&GPIO_InitStrue);
       
       
        USART_InitStrue.USART_BaudRate=9600;
        USART_InitStrue.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
        USART_InitStrue.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;
        USART_InitStrue.USART_Parity=USART_Parity_No;
        USART_InitStrue.USART_StopBits=USART_StopBits_1;
        USART_InitStrue.USART_WordLength=USART_WordLength_8b;
       
        USART_Init(USART2,&USART_InitStrue);
        USART_Cmd(USART2,ENABLE);
        USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
       
       
        NVIC_InitStrue.NVIC_IRQChannel=USART2_IRQn;
        NVIC_InitStrue.NVIC_IRQChannelCmd=ENABLE;
        NVIC_InitStrue.NVIC_IRQChannelPreemptionPriority=1;
        NVIC_InitStrue.NVIC_IRQChannelSubPriority=1;
        NVIC_Init(&NVIC_InitStrue);
       
       
}

void USART2_IRQHandler(void)
{
        u8 Res;
       if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
                {
                Res =USART_ReceiveData(USART2);       
//                        Res++;
                USART_SendData(USART2, Res);
                       
   }
}
这是usart的代码


hhhhhhhaa 发表于 2018-9-5 10:32:25

安 发表于 2018-9-5 10:20
估计还是编译器环境的配置问题。

环境哪里出问题了啊

hhhhhhhaa 发表于 2018-9-5 10:34:37

安 发表于 2018-9-5 10:20
估计还是编译器环境的配置问题。

看一下环境配置

jyl518-283289 发表于 2018-9-5 10:38:49

本帖最后由 jyl518-283289 于 2018-9-5 10:40 编辑

菜单Edition->Configuration,然后选择GB2312试试




toofree 发表于 2018-9-5 10:41:59



发表于 2018-9-5 10:42:24

本帖最后由 安 于 2018-9-5 10:44 编辑

网上好多解决办法的。一个一个测试一下。我试了一下,没有问题。

https://wenku.baidu.com/view/8e0 ... f9aef8941e48b8.html

用emwin做界面的时候遇到的错误,MDK5可能无法编译一些汉字编码,对应汉字在信息反馈中会显示为乱码,更会附带一些如“expected a "}"”这样的错误提示。解决方法:Options for Target “你的工程名”(MDK5的魔术棒) -> C/C++ -> Misc Controls添加“ --locale=english”

hhhhhhhaa 发表于 2018-9-5 10:42:35

jyl518-283289 发表于 2018-9-5 10:38
菜单Edition->Configuration,然后选择GB2312试试

一直都是这个
页: [1] 2
查看完整版本: main.c(20): error: #8: missing closing quote 出现这个错误是怎么回...