qingsongzdq 2020-04-20
一 你真正懂了C语言了吗?
很多人刚把c语言用了两年,就以为很懂,等遇到稍微深层次一点的问题,就卡住了。这里,有一个问题,可以考察你对这三者理解如何。
二 一个例子:
#include <stdio.h>
typedef unsigned char uint8_t;
typedef struct {
uint8_t ssid[32]; /**< SSID of ESP8266 soft-AP */
uint8_t password[64]; /**< Password of ESP8266 soft-AP */
} wifi_ap_config_t;
typedef struct {
uint8_t ssid[32]; /**< SSID of target AP*/
uint8_t password[64]; /**< password of target AP*/
} wifi_sta_config_t;
typedef union {
wifi_ap_config_t ap; /**< configuration of AP */
wifi_sta_config_t sta; /**< configuration of STA */
} wifi_config_t;
#define SSID "test"
#define PASSWD "1234567890"
int main()
{
wifi_config_t wifi_config = {
.sta = {
.ssid = SSID,
.password = PASSWD
},
};
printf("hello world");
}在你没有运行代码之前,能够看出来这个例子能够运行正确吗?有啥语法问题吗?
三 拓展问题
1 把这个结构体换成一个从数组中获取ssid和passwd,这个该怎么解决呢?写出你的代码。
2 把这个宏定义换成一个函数指针,从函数指针中获取ssid和passwd,这个代码该怎么改呢?写出你的代码。
假如你这两个都弄对了,恭喜你,说明你的c语言基础还真是不错的。