一个简单的VC++问题

来源:百度知道 编辑:UC知道 时间:2024/05/31 07:23:52
请编制函数StrOR( ),其函数的功能是:以行为单位依次把字符串中所有小写字母o左边的字符串内容移到该串的右边存放,然后把小写字母o删除,余下的字符串内容移到已处理字符串的左边存放,之后把已处理的字符串仍按行重新存入字符串数组xx中。最后main()函数调用函数
例如原文:n any field.Yu can create an index
you have the correct record.
结果:n any field. Yu can create an index
rd. yu have the crrect rec
最后要将经过函数处理的的一行一行的输出来

//done

#include <stdio.h>
#include <string.h>

#define STR_LENG 100
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))

char str_array[][STR_LENG] =
{
"n any field.Yu can create an index ",
"you have the correct record. "
};

void convert(char * str)
{
char *index = strchr(str, 'o');
int len = strlen(str);
int cnt;
char tmp[STR_LENG];

if (NULL == index)
{
return;
}
cnt = index - str;

memcpy(tmp, str, cnt);
memcpy(str, index + 1, len - cnt - 1);
memcpy(str + len - cnt - 1, tmp, cnt);

str[len - 1] = '\0';
}

void test(void)
{
for (int i = 0; i < ARRAY_LEN(str_array); i++)
{
char *index = strchr(str_array[i], 'o');

while (NULL != index)
{
convert(str_array[i]);
index = strchr(str_