Reputation: 2214
I need to place * on every lowercase letter, but my program blocks always. Although this seems like a simple problem I cant find simple solution. Please help.
#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;
}
I found some similar problems on internet but without success. :(
Upvotes: 2
Views: 126
Reputation: 400029
You cannot modify string literals.
Try:
int main(void)
{
char buf[] = "tesT";
f(buf);
return 1;
}
also, never hardcode ASCII values, use islower()
from <ctype.h>
.
Upvotes: 8