[note] 既然 typedef, 为何还要使用 define?

#define __ptr_t void *

而不是使用

typedef void * __ptr_t

因为对于 const __ptr_t
前者会直接展开为 const void *,解释为指向 const void的指针
而后面则相当于 void * const,解释为const指针,指向void

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include <stdio.h>#include <string.h>#include <stdlib.h>#define MAX_SMS_LENGTH 200#define MAX_NAME_LENGTH 8#define MAX_PHONE_LENGTH 11typedef struct { char word[MAX_SMS_LENGTH]; /*短信内容*/ int length; /*短信长度*/} Message;typedef struct { char name[MAX_NAME_LENGTH]; /*姓名*/ char phone[MAX_PHONE_LENGTH]; /*电话号码或手机号码*/} Note;void extract_phone_number(Message* message, Note* note) { int start = 0; int phone_start = -1; int phone_end = -1; while (start < message->length) { if (message->word[start] >= '0' && message->word[start] <= '9') { phone_start = start; phone_end = start; start++; while (start < message->length && message->word[start] >= '0' && message->word[start] <= '9') { phone_end = start; start++; } if (phone_end - phone_start == 6 || phone_end - phone_start == 7) { strncpy(note->phone, message->word + phone_start, phone_end - phone_start + 1); note->phone[phone_end - phone_start + 1] = '\0'; } else if (phone_end - phone_start == 10 || phone_end - phone_start == 11) { strncpy(note->phone, message->word + phone_start, phone_end - phone_start + 1); note->phone[phone_end - phone_start + 1] = '\0'; } if (strlen(note->phone) > 0) { break; } } else { start++; } }}void save_to_contact(Note* note) { // 将 note 存储到通讯录中}int main() { Message message; Note note; // 读取短信 fgets(message.word, MAX_SMS_LENGTH, stdin); message.length = strlen(message.word) - 1; message.word[message.length] = '\0'; memset(note.name, 0, MAX_NAME_LENGTH); memset(note.phone, 0, MAX_PHONE_LENGTH); extract_phone_number(&message, &note); save_to_contact(&note); return 0;}这个代码打开怎么使用
06-02

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值