资源加载 - 相对路径获取JAVA配置文件
2013-06-30 15:49
671 查看
以下使用strncpy 但不安全
以下用strncpy 我们认为它更安全
#include <stdio.h> #include <malloc.h> #include <string.h> #include <windows.h> int main (int argc, char *argv[]) { char *p = "hello who you are ? "; char *dest; char s[20]; int valLen; dest = (char *) malloc (sizeof (char) * 1000); //if we use strncpy_s we will get assert //for the size is not enough //we can just change s[20] to s[21] /* strncpy_s(s, _countof(s), p, strlen(p)); printf("%s\n", s); */ // Here we use strncpy and get null termination strncpy (dest, p, (valLen = strlen(p))); dest[valLen] = '\0'; printf ("%s\n", dest); //system ("pause"); return 0; }
以下用strncpy 我们认为它更安全
#include <stdio.h> #include <malloc.h> #include <string.h> #include <windows.h> int main (int argc, char *argv[]) { char *p = "hello who you are ? "; char *dest; char s[20]; int valLen; dest = (char *) malloc (sizeof (char) * 1000); //if we use strncpy_s we will get assert //for the size is not enough //we can just change s[20] to s[21] strncpy_s(s, _countof(s), p, strlen(p)); printf("%s\n", s); // Here we use strncpy and get null termination /* strncpy (dest, p, (valLen = strlen(p))); dest[valLen] = '\0'; printf ("%s\n", dest); */ //system ("pause"); return 0; }
相关文章推荐
- java获取当前路径及加载配置文件(报错:java.lang.NullPointerException java.util.Properties$LineReader.readLine(Prop)
- 相对路径获取JAVA配置文件Class.getResourceAsStream() & ClassLoader的getResourceAsStream()
- java获取当前路径及加载配置文件
- JAVA开发10--加载相对路径下配置文件并读取内容
- 文件的相对路径和绝对路径,加载资源文件失败
- spring-boot 加载本地静态资源文件路径配置
- 在JAVA文件中获取该项目的相对路径
- Java或者JAR包获取读取资源文件的路径的问题总结
- java 获取文件或资源的路径小结
- java取得项目工程---获取文件的相对路径问题---getResource()和getResourceAsStream以及路径问题
- java 使用递归获取指定文件路径目录,删除指定的文件后缀(可扩展,根据具体需要的删除的后缀进行配置)~~
- spring-boot 加载本地静态资源文件路径配置
- JAVA 获取web文件的相对路径
- Java或者JAR包获取读取资源文件的路径的问题总结
- 在JAVA文件中获取该项目的相对路径
- 转帖--在JAVA文件中获取该项目的相对路径
- Servlet(19)web.xml 配置之Servlet参数配置和读取资源文件,获取文件全路径
- 在java项目中通过相对路径获取资源的方式
- JAVA文件中获取该项目的相对路径方法
- java获取指定资源文件路径的几种方法