标签:就是 crt img printf http print 多个 行数据 场景
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<time.h> struct mycoach//mycoach是结构体类型,如果省略就是无名结构体 { //还可以包含其他结构体,其中每个元素的内存都相互独立 char name[30]; int age; }; void main() { struct mycoach cpc; sprintf(cpc.name,"陈培昌");//字符串不可以等号赋值,strcpy()---在string模块下 printf("\n%s",cpc.name); system("pause"); }
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<time.h> struct mycoach//mycoach是结构体类型,如果省略就是无名结构体 { //还可以包含其他结构体,其中每个元素的内存都相互独立 char name[30]; int age; char expertin[100]; }; void main() { struct mycoach cpc,xxd,wr,fgf; sprintf(cpc.name,"陈培昌");//字符串不可以等号赋值,strcpy()---在string模块下 printf("%s\n",cpc.name); system("pause"); }
#define _CRT_SECURE_NO_WARNINGS #define jl struct mycoach #include<stdio.h> #include<stdlib.h> #include<time.h> struct mycoach//mycoach是结构体类型,如果省略就是无名结构体 { //还可以包含其他结构体,其中每个元素的内存都相互独立 char name[30]; int age; char expertin[100]; }; void main() { jl cpc,xxd,wr,fgf; sprintf(cpc.name,"陈培昌");//字符串不可以等号赋值,strcpy()---在string模块下 printf("%s\n",cpc.name); system("pause"); }
#define _CRT_SECURE_NO_WARNINGS #define jl struct mycoach #include<stdio.h> #include<stdlib.h> #include<time.h> struct mycoach//mycoach是结构体类型,如果省略就是无名结构体 { //还可以包含其他结构体,其中每个元素的内存都相互独立 char name[30]; int age; char expertin[100]; }cpc, xxd, wr, fgf;//定义时,就声明变量 void main() { sprintf(cpc.name,"陈培昌");//字符串不可以等号赋值,strcpy()---在string模块下 printf("%s\n",cpc.name); system("pause"); }
结构体类型不分配内存,结构体变量分配,结构体类型不可以访问,赋值,存取,运算;成员名与类型名可以重名
#define _CRT_SECURE_NO_WARNINGS #define jl struct mycoach #include<stdio.h> #include<stdlib.h> #include<time.h> struct mycoach//mycoach是结构体类型,如果省略就是无名结构体 { //还可以包含其他结构体,其中每个元素的内存都相互独立 char name[30]; int age; char expertin[100]; }cpc, xxd, wr, fgf; void main() { struct mycoach cpc = {"陈培昌",22,"泰拳,散打"}; printf("%s\n", cpc.expertin); system("pause"); }
#define _CRT_SECURE_NO_WARNINGS #define jl struct mycoach #include<stdio.h> #include<stdlib.h> #include<time.h> struct mycoach//mycoach是结构体类型,如果省略就是无名结构体 { //还可以包含其他结构体,其中每个元素的内存都相互独立 char name[30]; int age; char expertin[100]; }cpc = { "陈培昌", 22, "泰拳,散打" }; void main() { printf("%s\n", cpc.expertin); system("pause"); }
#define _CRT_SECURE_NO_WARNINGS #define jl struct mycoach #include<stdio.h> #include<stdlib.h> #include<time.h> struct { //还可以包含其他结构体,其中每个元素的内存都相互独立 char name[30]; int age; char expertin[100]; }cpc; void main() { sprintf(cpc.name,"陈培昌"); cpc.age = 22; sprintf(cpc.expertin,"泰拳,散打"); printf("%s\n", cpc.expertin); system("pause"); }
another form
#define _CRT_SECURE_NO_WARNINGS #define jl struct mycoach #include<stdio.h> #include<stdlib.h> #include<time.h> struct { //还可以包含其他结构体,其中每个元素的内存都相互独立 char name[30]; int age; char expertin[100]; }cpc = { "陈培昌", 22, "泰拳,散打" }; void main() { printf("%s\n", cpc.expertin); system("pause"); }
结构体引用:无法整体引用,只能通过变量引用
#define _CRT_SECURE_NO_WARNINGS
#define jl struct mycoach
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
struct mycoach { //还可以包含其他结构体,其中每个元素的内存都相互独立 char name[30]; int age; char expertin[100]; };
void main()
{
struct mycoach cpc = { "陈培昌", 22, "泰拳,散打" }; //cpc = { "陈培昌", 22, "泰拳,散打" };//错误,{}初始化只能在声明变量时,使用
printf("%s\n", cpc.expertin);
system("pause");
}
标签:就是 crt img printf http print 多个 行数据 场景
原文地址:https://www.cnblogs.com/saintdingspage/p/11966293.html