首页 > 编程语言 > 详细

C语言:数组操作

时间:2021-08-10 16:54:26      阅读:14      评论:0      收藏:0      [点我收藏+]

1.字符数组赋值:char c1[20] = "women";

2。将数转为字符赋值给数组

#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
int main()
{
    char c1[20] = "women";
    int num=10,num1=101;
    char str[100];
    itoa(num,str,16);//将num转换化16进制赋值给str 
    printf("%s\n",str);
    itoa(num1,str,2);//将num转换化2进制赋值给str 
    printf("%s\n",str);
    char s[10];
    sprintf(s, "%d", 123); //产生"123",赋值给数组 
    printf("%s\n",s);
    sprintf(s, "%8d%8d", 123, 4567); //产生:" 123 4567" ,赋值给数组
    printf("%s\n",s);
    sprintf(s, "%-8d%8d", 123, 4567); //产生:"123 4567"
    printf("%s\n",s);
    sprintf(s, "%8x", 4567); //小写16 进制,宽度占8 个位置,右对齐
    printf("%s\n",s);
    sprintf(s, "%-8X", 4568); //大写16 进制,宽度占8 个位置,左对齐
    printf("%s\n",s);
    sprintf(s, "%08X", 4567); //产生:"000011D7"
    printf("%s\n",s);
    sprintf(s, "%08x", 4567); //产生:"000011D7"
    printf("%s\n",s);
    sprintf(s,"%7.2f",23.35);
    printf("%s\n",s);
      sprintf(s,"%.2f",23.35);
    printf("%s\n",s);
    getchar();
}

 

C语言:数组操作

原文:https://www.cnblogs.com/xkdn/p/15124099.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!