c - printing int array as string -


i trying print int array %s. not working. ideas why?

#include<stdio.h> main() {     int a[8];      a[0]='a';     a[1]='r';     a[2]='i';     a[3]='g';     a[4]='a';     a[5]='t';     a[6]='o';     a[7] = '\0';      printf("%s", a); } 

it prints a. tried short well, not work.

this because trying print int array, each element has size of 4 byte (4 chars, on 32bit machines @ least). printf() interprets char array first element looks like:
'a' \0 \0 \0
printf(). printf() stops @ first \0 finds, prints 'a'.

use char array instead.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -