📄 convstrn.c
字号:
/* ******************************************************************
* Function name : str_convert(string)
*
* Description : This function is used to convert lower
* case alpha character to upper case and
* upper case alpha characters to lower case.
*
* Variables : string - This parameter is a character
* pointer to the string that is to be
* modified.
*
* Example : strcpy(str,"ABC");
* output = str_convert(str); returns the string abc
* strcpy(str,"abC");
* output = str_convert(str); returns the string ABc
*
* Rules : 1) The function must be passed a character pointer
* containing the address of the character string to
* be converted.
*
* 2) This function does not use a return value. Therefore
* it may be defined using the "void" data type if
* it is supported by your compiler.
*
*
*/
str_convert(string)
char string[];
{ int count;
count = 0;
while ( string[count] != '\0' )
{ if ( string[count] >= 'A' && string[count] <= 'Z' )
string[count] = string[count] + 'a' - 'A';
else
if ( string[count] >= 'a' && string[count] <= 'z' )
string[count] = string[count] - 'a' + 'A';
count++;
}
}
/* ******************************************************************
* Function name : str_count(string)
*
* Description : This function counts the number of characters
* contained within a specified character string.
*
* Variables : string - This parameter is a character
* pointer to the string that is to be
* counted.
*
*
* Example : str_convert("abcd"); returns a 4
* str_convert("ab"); returns a 2
*
* Rules : 1) The function must be passed a character pointer
* containing the address of the character string
* being analyzed.
*
* 2) The return value must be passed to an integer
* variable.
*
* 3) The string being analyzed must be followed
* by a null terminator "\0" value.
*
*
*/
str_count(string,sub_string)
char string[];
char sub_string;
{ int count, index;
count = index = 0;
while ( string[count] != '\0' )
{ if ( string[count++] == sub_string ) index++;
}
return(index);
}
/* ******************************************************************
* Function name : str_lindex(string, sub )
*
* Description : This function returns an integer value, indicating
* the first location of the specified sub-string
* character within the string being analyzed.
*
* Variables : string - This parameter is a character
* pointer to the string that is to be
* counted.
*
* sub - This parameter contains the character
* being searched.
*
* Example : output = str_convert("abcde",'c'); returns a 3
* output = str_convert("abcd",'d'); returns a 4
* output = str_convert("abcd",'b'); returns a 2
*
* Rules : 1) The function must be passed a character pointer
* containing the address of the character string
* being analyzed.
*
* 2) The return value of this funtion must be passed
* to an integer variable.
*
* 3) The string being analyzed must be followed
* by a null terminator "\0" value.
*
*/
str_lindex(string,sub_string)
char string[];
char sub_string;
{ int index;
index = 0;
while ( string[index] != '\0' && string[index] != sub_string)
++index;
return(index);
}
/* ******************************************************************
* Function name : str_delete(string, start, no_char)
*
* Description : Thi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -