typedef 字符串_typedef在C中使用字符数组(定义别名来声明字符串)的示例

typedef 字符串

Here, we have to define an alias for a character array with a given number of maximum characters length to read strings?

在这里,我们必须为具有给定最大字符长度数的字符数组定义别名,以读取字符串

In the below-given program, we have defined two alias (typedefs) for character array and unsigned char:

在下面给出的程序中,我们为字符数组和无符号字符定义了两个别名(typedef):

    typedef char CHRArray[MAXLEN];
typedef unsigned char BYTE;

MAXLEN is also defined with 50 by using define statement #define MAXLEN 50.

MAXLEN还与50通过定义语句的#define MAXLEN 50界定。

Declaring variables:

声明变量:

    CHRArray name;
CHRArray city;
BYTE age;

Explanation:

说明:

CHRArray name will be considered as char name[50], CHRArray city will be considered as char city[50] and BYTE age will be considered as unsigned char age.

CHRArray名称将被视为char name [50] , CHRArray city将被视为char city [50] , BYTE age将被视为unsigned char age 。

Note: unsigned char is able to store the value between 0 to 255 (i.e. one BYTE value).

注意: unsigned char能够存储0到255之间的值(即一个BYTE值)。

Program:

程序:

#include <stdio.h>
#include <string.h>
#define MAXLEN 50
typedef char CHRArray[MAXLEN];
typedef unsigned char BYTE;
int main()
{
CHRArray name;
CHRArray city;
BYTE age;
//assign values
strcpy(name, "Amit Shukla");
strcpy(city, "Gwalior, MP, India");
age = 21;
//print values
printf("Name: %s\n", name);
printf("city: %s\n", city);
printf("Age : %u\n", age);
return 0;
}

Output

输出量

Name: Amit Shukla
city: Gwalior, MP, India
Age : 21

翻译自: https://www.includehelp.com/c-programs/typedef-example-with-character-array-define-an-alias-to-declare-strings.aspx

typedef 字符串

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/376961.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

最小堆实现代码

参考算法导论、数据结构相关书籍&#xff0c;写得最小堆实现的源代码如下&#xff1a; 1 //2 //--最小堆实例3 //4 5 #include <iostream>6 #include <vector>7 #include <string>8 using namespace std;9 10 template<typename Comparable>11 class m…

非常好的在网页中显示pdf的方法

今天有一需求&#xff0c;要在网页中显示pdf&#xff0c;于是立马开始搜索解决方案&#xff0c;无意中发现一个非常好的解决方法&#xff0c;详见http://blogs.adobe.com/pdfdevjunkie/web_designers_guide。 其实就光看这个网站也足够了&#xff0c;http://www.pdfobject.com/…

Redis字典实现、Hash键冲突以及渐进式rehash

本笔记参考《Redis设计与实现》 P24~ 37 目录Redis字典实现哈希表节点结构哈希表结构字典哈希算法解决hash冲突rehash渐进式hashRedis字典实现 哈希表节点结构 typedef struct dictEntry {// 键void *key;// 值 : 可以是一个指针&#xff0c;或者是一个uint64/int64 的整数un…

Java线程类void setContextClassLoader(ClassLoader loader)方法,带示例

线程类void setContextClassLoader(ClassLoader loader) (Thread Class void setContextClassLoader(ClassLoader loader)) This method is available in package java.lang.Thread.setContextClassLoader(ClassLoader loader). 软件包java.lang.Thread.setContextClassLoader(…

JPA概要

本文最新版已更新至&#xff1a;http://thinkinside.tk/2012/12/30/JPA.html JPA定义了Java ORM及实体操作API的标准。本文摘录了JPA的一些关键信息以备查阅。 如果有hibernate的基础&#xff0c;通过本文也可以快速掌握JPA的基本概念及使用。 Table of Contents 1 JPA概述2 实…

如何配置能让fiddler抓去https的请求?

1、打开fiddler&#xff0c;>>Tools>>Fiddler Options&#xff0c; 打开如图所示的HTTPS配置项&#xff1a;点击Export Rppt Certifica to Desktop :桌面上多了一个证书&#xff1a;下面就是将证书导入&#xff1a;点击开始-运行&#xff0c;输入&#xff1a;mmc,…

Redis对象的refcount与lru属性(内存回收、对象共享、空转时长)

本笔记参考《Redis设计与实现》 P84~P88 内存回收 Redis在对象系统中使用reference counting技术实现了内存回收机制。程序可以通过跟踪对象的引用计数信息&#xff0c;在适当的时候自动释放对象并进行内存回收。 typedef struct redisObject {// ...// 引用计数int refcoun…

【闲聊】Baidu Map,excellent !!!Diaoyv island is China 's

【钓鱼岛】钓鱼岛是中国的&#xff01;Diaoyu Islands are Chinas! 釣魚島は中国のアール! ————————————youngLaker转载于:https://www.cnblogs.com/younglaker/archive/2012/12/31/2840190.html

08:vigenère密码_密码技术:Vigenére密码,Playfair密码,Hill密码

08:vigenre密码1)Vigenre密码 (1) Vigenre Cipher) This technique is an example of Polyalphabetic Substitution technique which uses 26 Caesar ciphers make up the mono-alphabetic substitution rules which follow a count shifting mechanism from 0 to 25. That is,…

Redis的RDB文件与AOF文件

本笔记参考《Redis设计与实现》 P118 ~ P150 RDB文件 1、RDB文件用于保存和还原Redis服务器所有数据库中的所有键值对数据 2、SAVE命令由服务器进程直接执行保存操作&#xff0c;该命令会阻塞服务器 3、BGSAVE命令由子进程执行保存操作&#xff0c;不会阻塞服务器 注意此时服…

eclipse扩容

eclipse扩容 -vmD:/jdk-6u17-windows-i586/jdk1.6.0_17/bin/javaw.exe-startupplugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar-nlen_US--launcher.libraryplugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20120913-144807-productorg.eclipse…

node oauth2验证_如何设置和使用护照OAuth Facebook身份验证(第2部分)| Node.js

node oauth2验证In my last article (How to set up and use passport OAuth Facebook Authentication (Section 1) | Node.js), we looked at another form of authentication called the OAuth authentication which involves sign in or signup using social media. 在我的上…

Python and Microsoft Word

国外网站看到的文章&#xff1a;Accessing Microsoft Word with Python follows the same syntax that we used for Excel. Let’s take a quick look at how to access Word.from time import sleep import win32com.client as win32RANGE range(3, 8)def word():word win32…

东哥读书小记 之 《一个广告人的自白》

掰着指头一算&#xff0c;端午假期确实完成不少事情&#xff0c;过的太尼玛充实鸟&#xff1a;去健身房2小时&#xff0c;且老夫的平板支撑终于能坚持超过1分钟&#xff0c;普大喜奔有木有&#xff1b;给合租的室友买蛋糕过了个生日&#xff1b;去 去哪儿 参加W3ctech的技术交流…

Redis的文件事件与时间事件处理

目录文件事件处理事件类型客户端和服务端的通信过程时间事件处理执行器执行周期性事件作用事件的调度与执行文件事件处理 Redis基于Reactor模式开发了文件事件处理器。文件事件处理器以单线程方式运行&#xff0c;通过IO多路复用程序监听多个套接字&#xff0c;实现了高性能网…

fisher-yates_使用Fisher-Yates随机播放算法以O(n)时间随机播放给定数组

fisher-yatesExample: 例&#xff1a; Say the input array is [1, 2 3, 4, 5 6, 7]After reshuffling it can be anything like[4, 3, 7, 2, 1, 5, 1]Our goal is that the reshuffling should be as random as possible. 我们的目标是&#xff0c;改组应尽可能地随机。 The…

[分享]一些在 WPF/Silverlight 中应用 MVVM 模式时可能会有点用途的代码

想来这个博客也已经有很久没更新过了&#xff0c;新年新气象&#xff0c;现在就开始写新内容吧。 最初的起因 在最近的几个月中我做的开发总是要跟 XAML 打交道&#xff0c;也就是 WPF 啊&#xff0c;Silverlight 啊&#xff0c;WF 啊这些。 在进行 WPF 和 Silverlight 开发的…

手机调用系统的拍照和裁剪功能,假设界面有输入框EditText,在一些手机会出现点击EditText会弹出输入法,却不能输入的情况。...

1、拍照裁剪后 点击EditText会弹出输入法&#xff0c;却不能输入。可是点击点一EdtiText就能够输入了&#xff0c;所以我就写了一个看不见的EdtiText&#xff0c;切换焦点&#xff0c;这样就攻克了这个奇怪的这问题&#xff0c;应该是android内部的问题。 这是网络一个牛人留下…

Redis一个命令请求从发送到完成的步骤以及初始化服务器步骤

一个命令请求从发送到完成的步骤 如下&#xff1a; 1、客户端将命令请求发送给服务器 当用户在客户端中键入一个命令请求时&#xff0c;客户端会将这个命令请求转换成协议格式&#xff0c;然后通过连接到服务器的套接字&#xff0c;将协议格式的命令请求发送给服务器。 2、服…

c打印行号和函数_使用C中的函数名称,行号从任何函数打印错误消息

c打印行号和函数Sometimes, it is necessary to print some message on logic failure or anytime with the function name and line number, so that program can be debugged and fixed the issue. 有时&#xff0c;有必要在逻辑故障时或在任何时候使用功能名称和行​​号打印…