why i scanf in c language with int variable of any char and printf with %d it must show 2? -


my code is

#include <stdio.h> int main() {     int name;     scanf("%d",&name);     printf("%d",name); } 

why when enter "hello","world","good", etc must show 2 ? why 2 not other number ? if want scanf string , printf ascii code of how should ? thankyou

to print ascii values of entered string :

#include <stdio.h> #include <stdlib.h> #include <string.h>  int main(){   char array[100];        int i=0;     printf("enter string : ");     scanf("%s",array);    // fixed suggested in comments      for(i=0;i<strlen(array);i++){          printf("%d-",array[i]);      }     printf("\n");     return 0; } 

output of code:

enter string : hello 104-101-108-108-111- 

edit:

as pointed out folks in comments ... make sure array size defined value think input size never exceed ...


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -