【发布时间】:2014-10-24 18:44:51
【问题描述】:
我在 Ansi C 中遇到了这个问题
3 创建一个函数,该函数接收每个解码的 20 个字符的字符串数组,考虑以下几点:
一种。从左到右阅读,数字表示从那里要投资多少个字符(要投资的字符之间可以是数字,大意是,
被认为是常见字符)。
湾。数字字符应替换为反转字符串的第一个字符。
示例。字符串 aj5pr2*dfkl3abc2qwe1azk 必须是 ajd*2rpfklcbawqeazk
使用符号和指针算术
#include <stdio.h>
#include <string.h>
#define TAM 20
char* invertNumerSubstrings(char*);
int main()
{
char chain[TAM];
printf("\n Ingrese chain: ");
gets(chain);
fflush(stdin);
char result;
result=invertNumerSubstrings(chain);
printf("\n Chain modified: ");
puts(chain);
printf("\n");
return 0;
}
char* invertNumerSubstrings(char* chain)
{
int flag =0;
char *pl= chain;
char *pe= chain;
char aux;
while(*pl=='\0'&& *pe=='\0');
{
if(!(*pl=='1')&&(*pe=='9'))
{
pl++;
pe++;
}
else
{
if(flag ==0)
{
pe=*pl;
flag=1;
pl--;
}
if(*pe<*pl)
{
aux=*pl;
*pl=*pe;
*pe=aux;
}
}
}
return *chain;
}
这个程序没有编译错误但没有工作
【问题讨论】: