pointer on C programming exercise P6.18 Q2
来源:互联网 发布:胡夫金字塔的结构数据 编辑:程序博客网 时间:2024/05/22 17:45
/****************************************file name:****************************************//****************************************include files****************************************/#include "stdio.h"/****************************************function declaration****************************************/int delete_substr(char *source, char const *chars);/****************************************function realization****************************************/int main(void){ int iReturn = 0; char *ppStr[] = { "ABCDEFG", // 0 "FGH", // 1 "CDF", // 2 "XABC", // 3 "CDE", // 4 NULL // 5 }; //abnormal test iReturn = delete_substr(NULL, NULL); iReturn = delete_substr(NULL, ppStr[0]); iReturn = delete_substr(ppStr[0], NULL); iReturn = delete_substr(ppStr[5], ppStr[0]); iReturn = delete_substr(ppStr[0], ppStr[5]); //normal test iReturn = delete_substr(ppStr[0], ppStr[1]); iReturn = delete_substr(ppStr[0], ppStr[2]); iReturn = delete_substr(ppStr[0], ppStr[3]); iReturn = delete_substr(ppStr[0], ppStr[4]); if(1 == iReturn) { printf("delete success: %s, substr %s\n", ppStr[0], ppStr[4]); } return 0;}/****************************************name: delete_substr*function: delete sub string if found****************************************/int delete_substr(char *pSource, char const *pChars){ char *pSrcloc = NULL; // pointer to the source string in inter loops char *pSubloc = NULL; // pointer to the destination string in inter loops char *pSrcstr = NULL; // pointer to the source string in outer loops int bFind = 0; // flag indicates if find the substring. //check parameter if((NULL == pSource) || (NULL == pChars) || (NULL == *pSource) || (NULL == *pChars)) { return 0; } //inter loops tracks source string pSrcstr = pSource; while(*pSrcstr) { if((*pSrcstr) == (*pChars)) { //find the matched char position pSrcloc = (char *)pSrcstr; pSubloc = (char *)pChars; while(*pSubloc) { if(*pSubloc != *pSrcloc) { //search end, doesn't match bFind = 1; break; } else { //match the next char pSubloc++; pSrcloc++; } } //check if find if(0 == bFind) { //delete the substring pSubloc = (char *)pChars; while(*pSubloc) { *pSrcstr = *pSrcloc; pSrcstr++; pSubloc++; pSrcloc++; } //clear the tail of source string while(*pSrcstr) { *pSrcstr = '\0'; pSrcstr++; } return 1; } else { // substr fait to match pSrcstr++; } } else { pSrcstr++; } } return 0;}
0 0
- pointer on C programming exercise P6.18 Q2
- pointer on C programming exercise P6.18 Q1
- pointer on C programming exercise P6.18 Q3
- Pointer On C-1.1
- pointer on c
- The C programming language-Exercise 1-9
- The C Programming Language Exercise 2_6
- Some Exercises about Pointer (C Programming)
- C Programming Language: Function Pointer Array Study
- Notes on Programming in C
- Notes on Programming in C
- Notes on Programming in C
- Notes on Programming in C
- The amazing efficiency of pointer in C Programming Language
- The function that returns the pointer (C Programming)
- 15 Free eBooks on C Programming
- Notes on C programming language (0)
- Socket programming in C on Linux | tutorial
- sqlite3 按编辑框中的输入值查找数据库相符内容
- zigbee 2:OSAL概要
- 表单中的文本框(input)禁止自动完成下拉框显示(兼容ie/firefox/ff)
- 修改浏览器快捷方式的启动参数
- IOS开发BUG集锦_20150204
- pointer on C programming exercise P6.18 Q2
- Mysql慢查询日志
- Download Protocol Buffers
- cx_Oracle Oracle home does not refer to an 8i, 9i, 10g or 11g installation
- java 把数据填充到表格EXL中
- java 学习笔记3
- Decode Ways --- LeetCode
- 【POJ1681】Painter's Problem 高斯消元,求最小∑系数的异或方程组
- timestamp应用——乐观锁和悲观锁【转】