I would like print the following char Array.
#define LENGTH 8
int main (){
typedef char Arr[LENGTH];
Arr test = {1,0,1};
Arr* a = &test;
for(int i=0;i<LENGTH;i++){
printf("%s ", a[i]);
}
}
fixing your many errors and re-editing to use strlen:
#define LENGTH 8
#include <stdio.h>
#include <string.h>
int main()
{
typedef char Arr[LENGTH];
Arr test = {'1','0','1'};
Arr* a = &test;
size_t len = strlen(test);
for(int i=0;i<len;i++){
printf("%c ", (*a)[i]);
}
}
Three problems:
%s
, which is for strings. Use %c
for characters.(*a)[i]
, as a
is a pointer to an array, so *a
is an array.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.