'Faced an error: excess elements in char array initializer during print out of array of strings
I've tryed to print out some array of strings but faced error: excess elements in char array initializer Please make a hint what's worng with this code?
Step 1 change '' with "" nothing changed, the same error. Step 2 change maschar to *maschar, it helped, thaks.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char maschar[] = {'char', 'mas', 'got'};
int lenchar = sizeof(maschar) / sizeof(*maschar);
for (int i = 0; i< lenchar; i++)
printf("%s\n", *(maschar+i));
return 0;
Solution 1:[1]
Step 1 change '' with "" nothing changed, the same error. Step 2 change maschar to *maschar, it helped, thaks.
char *maschar[] = {"char", "mas", "got"};
int lenchar = sizeof(maschar) / sizeof(*maschar);
for (int i = 0; i< lenchar; i++)
printf("%s\n", *(maschar+i));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | whocares |