0

I am trying to mod a char in c by using the following:

int shift = 1;    
c = (c + shift ) % 26;
printf("c= %c \n",c);

The variable c is a lowercase english character between a-z. When I try to print out the char c using the above code, I get the following:

c=  

Could someone please tell me what I am doing wrong?

Turtle
  • 1,369
  • 1
  • 17
  • 32

1 Answers1

0

Shift it by 'a' or 'A'. Then you'll always get a character that's part of the alphabet:

int main(){
    unsigned i;
    for(i=0;;i++)
        printf("i=%c\n", 'a'+i%26);

 }

prints:

i=a
i=b
i=c
i=d
i=e
i=f
i=g
i=h
i=i
i=j
...
Petr Skocik
  • 58,047
  • 6
  • 95
  • 142