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?
在這里,我們必須為具有給定最大字符長度數(shù)的字符數(shù)組定義別名,以讀取字符串 ?
In the below-given program, we have defined two alias (typedefs) for character array and unsigned char:
在下面給出的程序中,我們?yōu)樽址麛?shù)組和無符號(hào)字符定義了兩個(gè)別名(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能夠存儲(chǔ)0到255之間的值(即一個(gè)BYTE值)。
Program:
程序:
#include <stdio.h> #include <string.h>#define MAXLEN 50typedef char CHRArray[MAXLEN]; typedef unsigned char BYTE;int main() {CHRArray name;CHRArray city;BYTE age;//assign valuesstrcpy(name, "Amit Shukla");strcpy(city, "Gwalior, MP, India");age = 21;//print valuesprintf("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 字符串
總結(jié)
以上是生活随笔為你收集整理的typedef 字符串_typedef在C中使用字符数组(定义别名来声明字符串)的示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: _thread_in_vm_Java T
- 下一篇: 光与夜之恋装扮系统怎么解锁