码迷,mamicode.com
首页 > 其他好文 > 详细

printf 和sprintf

时间:2017-07-18 23:09:59      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:对齐   for   scanf   数字   style   取字符串   pause   ble   nbsp   

1.

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

void main(){

char l_str1[ ]="你好 "

char l_str2[ ]="吃饭了吗?"

char l_str3[100={0};

sprintf(l_str3,"%s%s",l_str1, l_str2);

system("pause");

}

 

2.#include<stdio.h>

#include<stdlib.h>

# include<string.h>

void main(){

char l_str1[ ]="123456“;

char l_str3[ ]={0};

sprintf(l_str 3,"%.4s",l_str1);//取字符串左边

or printf(l"%s\n",l_str1+2)//取字符串右边3456)

printf("%p\n",l_str1)//打印指针

system("pause");

}

 

3.#include<stdio.h>

#include<stdlib.h>

void main(){

for(size_t i=0;i<101;i++){

printf("%3d\n",i) //打印对齐三位数字从1-101

system("pause");

}

 

4.

double l_d=12340000;

printf("%e",l_d)//指数1.234xe^7

 

5.

 

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

void main(){

char l_input[100]={0};

char l_str[100]={0};

printf("请输入第一个颜色:");

scanf("%s",&l_input);

sprintf(l_str,"color%s",l_input);

system("l_str");

system("pause");

}

 

6.

#include<stdio.h>

#nclude<stdlib.h>

#include<string.h>

void main(){

printf("请输入一个表达式:");

char l_str1[100]={0};

char l_str2[100]={0};

scanf("%s",&l_str 1);

sprintf(l_str2,"set A%s",l_str1 );

system(l_str2);

system("pause");

}

 

printf 和sprintf

标签:对齐   for   scanf   数字   style   取字符串   pause   ble   nbsp   

原文地址:http://www.cnblogs.com/lenaben/p/7203223.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!