I’m trying to print an array of characters in C but i can’t print everything.
I want to print :
b1
b2
My code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char def[3][10]; //define a multidimensional array of characters
strcpy(def[0],"b1"); //insert "b1" at first line
strcpy(def[1],"b2"); //insert "b2" at first line
printf("%s",def); //print everything?
}
The above code prints just b1. I already tried :
printf("%s",def[0]);
printf("%s",def[1]);
But i have error “invalid use of array with unspecified bounds”
%sconversion specification expects a string.defis an array of strings and not a string.To print the first string do this:
if you want to print the second string then do this:
and if you want to print both strings:
To print all strings in your array: