snprintf不能使用"字符串指针"赋值,可以使用字符数组
#cat snprintf.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student{
int age;
char *name;
};
int main(void)
{
/*t1 结构体指针*/
struct student *t1;
t1 = malloc(sizeof(struct student));
t1->age = 11;
t1->name = "ahao.mah";
/*t2 结构体变量*/
struct student t2;
t2.name = "jack";
t2.age = 22;
printf("t1:%s\n", t1->name);
printf("t2:%s\n", t2.name);
/*snprintf不能使用字符串指针赋值*/
char *a;
char *dev = t1->name;
/*可以使用字符串数组*/
//char dev[10];
//strcpy(dev, t1->name);
printf("dev:%s\n", dev);
sprintf(a, "/dev/%s", dev);
printf("a:%s\n", a);
return 0;
}
snprintf不能使用"字符串指针"赋值,可以使用字符数组的更多相关文章
- 【转】C语言中,为什么字符串可以赋值给字符指针变量
本文是通过几篇转帖的文章整理而成的,内容稍有修改: 一. C语言中,为什么字符串可以赋值给字符指针变量 char *p,a='5';p=&a; //显然 ...
- C语言中,为什么字符串可以赋值给字符指针变量
转载于:http://www.cnblogs.com/KingOfFreedom/archive/2012/12/07/2807223.html 本文是通过几篇转帖的文章整理而成的,内容稍有修改: 一 ...
- char型指针和字符串字面量和字符数组
1.当一个char型指针指向一个字符串字面量(也就是常量字符串)时,该指针必须由const修饰,否则,系统会给出deprecated(不赞成)的警告.原因是:字符串字面量不可改变,当它被一个非cons ...
- String中的toCharArray:将此字符串转换为新的字符数组,并统计次数
package stringyiwen; public class StringTestToCharArray { public static void main(String[] args) { S ...
- Delphi字符串、PChar与字符数组之间的转换
来自:http://my.oschina.net/kavensu/blog/193719 ------------------------------------------------------- ...
- Delphi的字符串、PChar和字符数组之间的转换
参考:http://my.oschina.net/kavensu/blog/193719 以下的各种方法都是我在Delphi 6的环境下测试成功的,可能根据你的开发环境.不同的上下文语境……有一些可能 ...
- C#List转字符串,字符串转List,字符数组转Int数组
List转字符串 [C#] 纯文本查看 复制代码 ? 01 02 List<string> List = new List<string>(); string strArray ...
- JAVA实现字符串反转,借助字符数组实现
public static String reverseStr(String str) { int len = str.length(); char ch[] = str.toCharArray(); ...
- C语言字符数组和字符串
用来存放字符的数组称为字符数组,例如: char a[10]; //一维字符数组 char b[5][10]; //二维字符数组 char c[20]={'c', ' ', 'p', 'r', 'o' ...
随机推荐
- 【Android】资源系列(一) -- 国际化(多语言)
1.Android 中要实现国际化比較简单. 字符串国际化:仅仅要在 res 目录下新建相应语言的 values 目录就好了. 如.英语环境下的.目录命名为:values-en ...
- about service in android
注意:标红处! A Service is an application component representing either an application's desire to perform ...
- c++ vector数组的定义使用
/* *********************************************** Author :guanjun Created Time :2017/3/18 13:32:52 ...
- There was a conflict between
解读,首先搜索到第一个5>的开头的那一行,确认是在编译哪一个项目. 那么后面的冲突,就是在和这个项目冲突. There was a conflict between "log4net, ...
- U3D版本控制设置 Force Text优劣
git的忽略列表 .gitignore Library/ Temp/ .vs/ *.csproj *.sln Edit > Project Settings > Editor 下把meta ...
- 理解JavaScript中的闭包
(这篇文章后面关于onclick事件的解释是错误的,请不要被误导了2016.6.16) 闭包这个概念给JavaScript初学者心中留下了巨大的阴影,网络上关于闭包的文章不可谓不多,但是能让初学者看懂 ...
- vue-router路由加载两种模式
路由安装npm install --save vue-router 安装完成后,打开package.json,如果看到这个"vue-router": 版本号, 就代表安装成功了 ...
- SpringBoot集成Mybatis配置动态数据源
很多人在项目里边都会用到多个数据源,下面记录一次SpringBoot集成Mybatis配置多数据源的过程. pom.xml <?xml version="1.0" encod ...
- C# 工厂单例
public class BusinessFactory { private static BusinessFactory instance = null; pri ...
- 常用mysql记录
多个关键词 like$joinwhere .=" and CONCAT(`JpTel`,`JpName`) Like '%$keywords%' ";