答案: exercise for string functions in c run-time library
来源:互联网 发布:中标数据网官网 编辑:程序博客网 时间:2024/05/09 12:43
下面是参考答案:
以下问题,请把答案手工写在纸上,考察的内容是c run-time library,请不要使用其他库和接口。
要求:a) 每个人独立完成,b) 可以参考书和电子文档,c) 明天9:00之前完成
答题纸交给牟凤林。
1 在下面的代码中,要求复制一个内容一样的字符串,使用什么函数? 在空格处填上函数名称。
char* _pszA = "abcdefg";
char* _pszAnotherA = strdup(_pszA); // 目的:_pszAnotherA 的内容和 _pszA 一样。
2 刚才得到的 _pszAnotherA 需要是否需要释放内存?怎么释放?
是的,需要用free函数释放。注:malloc/free是c run-time lib标准的内存申请/释放函数。
3 说明strcmp, stricmp, strncmp, strnicmp的功能和区别。
略
4 说明_tcscpy, strcpy的区别。
略
5 下面的程序有什么问题? 怎么改正?
void show_message(char* pszInfo_)
{
char _szBuffer[128];
strcpy(_szBuffer, pszInfo_);
//...以下省略
}
void show_message(char* pszInfo_)
{
char _szBuffer[4];
if (pszInfo_)
{
strncpy(_szBuffer, pszInfo_, sizeof(_szBuffer));
_szBuffer[sizeof(_szBuffer) - 1] = 0;
}
else
{
_szBuffer[0] = 0;
}
}
6 下面的程序有什么问题? 怎么改正?
char* _pszA = "My name is: <your name here> ";
char* _pszB = "Bob";
strncpy(_pszA + sizeof("My name is: "), _pszB, 3);
char _pszA[] = "My name is: <your name here> ";
char* _pszB = "Bob";
strcpy(_pszA + sizeof("My name is:"), _pszB); // 注意: "My name is:" 不是 "My name is: "
7 举例说明strcat的用法。
略
8 写个函数,输入某个串,从开始到结束依次打印出其中每个字母a或b或c出现的位置(请使用for循环和合适的字符串函数完成)。
void test8(const char* pszBuffer_)
{
char _szSet[] = "abc";
for (char* _p = strpbrk(pszBuffer_, _szSet); _p; _p = strpbrk(_p + 1, _szSet))
{
printf("%d ", _p - pszBuffer_);
}
}
9 举例说明strtok的用法。
略
10 写个函数,输入某个串,把其中每个"abc"子串都改成"123"然后打印出来(请使用for循环和合适的字符串函数完成)。
void test10(char* pszBuffer_)
{
char _szSub[] = "abc";
int _len = sizeof(_szSub) - 1;
for (char* _p = strstr(pszBuffer_, _szSub); _p; _p = strstr(_p + _len, _szSub))
{
strncpy(_p, "123", _len);
}
}
- 答案: exercise for string functions in c run-time library
- exercise for string functions in c run-time library
- exercise for memory-allocation functions in c run-time library
- exercise for data conversion functions in c run-time library
- exercise for printf functions in c run-time library
- Win32 Equivalents for C Run-Time Functions
- C Run-time library
- C run-time library
- C run-time library
- CRT (C run-time library)
- CRT (C run-time library)
- CRT (C run-time library)
- 如何理解C run-time library
- 如何理解C run-time library
- 如何理解C run-time library
- C Run-Time Library的理解
- Removing the C run-time library (RTL)
- C Run-Time Library的理解
- JAVA学习提高之---- FileUpload组件实现多文件上传(JSP+SERVLET)实现
- 2008下半年,来自百度的博客
- 郭台铭说实话 科技新贵鸣悲歌/鸿海人的寒冬告白
- 好傻的bug后
- 经常被测试人员忽略的测试工具
- 答案: exercise for string functions in c run-time library
- 一个背景变暗的div可拖动提示窗口,兼容IE、Firefox、Opera
- 今晚的练习
- [SQL Server]管理常用SQL语句
- js 中 坐标 参数
- Javascript压缩工具(Javascript compressed,Js压缩)
- exercise for memory-allocation functions in c run-time library
- exercise for data conversion functions in c run-time library
- SQL Server 2000 注入防护大全