Iva*_*vić 2 c arrays ascii pointers
我需要在每个小写字母上放置*,但我的程序总是阻塞.虽然这似乎是一个简单的问题,但我找不到简单的解决方案.请帮忙.
#include <stdio.h>
void f(char *p)
{
int i = 0;
char c = '*';
while(p[i] != '\0')
{
if(p[i]> 96 && p[i] < 122 )
{
p[i] = c; # here program block
}
i++;
}
printf("%c",p);
}
int main(void)
{
f("tesT");
return 1;
}
Run Code Online (Sandbox Code Playgroud)
我在互联网上发现了一些类似的问题但没有成功.:(
您无法修改字符串文字.
尝试:
int main(void)
{
char buf[] = "tesT";
f(buf);
return 1;
}
Run Code Online (Sandbox Code Playgroud)
另外,不要硬编码的ASCII值,使用islower()从<ctype.h>.