Anup Buchke
Anup Buchke

Reputation: 5510

Printing C array on Console

#include <stdio.h>

int main(void) {
    // your code goes here

    char d[] = {1, 2, 3, 4, 5,6};

    printf("%s" ,d);
    int i ;
    for(i = 0; i < 6 ; i++)
        printf("%c " , d[i]);

    printf("\n");

    return 0;
}

I tried this small snippet on ideone.com. I was not able to get any output on console. Can someone please let me know whats wrong here?

Upvotes: 0

Views: 2889

Answers (1)

Andrea Bergia
Andrea Bergia

Reputation: 5552

Replace this:

    printf("%c " , d[i]);

with

    printf("%d " , (int)d[i]);

Assuming you want to treat the items in d as numbers.

Upvotes: 3

Related Questions