user466534
user466534

Reputation:

char printable program

i have program which prints all char from char_min to char_max here is code

#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
int main(){
    char c;
    c=CHAR_MIN;
     while(c!=CHAR_MAX){
          printf("d\n",c);
          c=c+1;

     }


return 0;



}

but it prints only all d why?ouput is like this

d
d
d
d
d
d
d
d
d
d

...

. . press any key to continue

Upvotes: 0

Views: 136

Answers (2)

James Curran
James Curran

Reputation: 103535

printf("d\n",c);     /// Means just print "d" (c is ignored)
printf("%d\n",c);     /// Means print the decimal value of varaible c
printf("%c\n",c);     /// Means print the charcter value of varaible c

Using "%d" will just print "0", "1", "2" etc.

Using "%c" will print the character values: "A", "B", "C" etc. Note, however, that the first 31 aren't printable.

Upvotes: 6

Jigar Joshi
Jigar Joshi

Reputation: 240928

replace

 printf("d\n",c);

with

printf("%c\n",c);

Upvotes: 2

Related Questions