Skip to content
← Back to Community
A Noobs errors
Profile icon

So uh. I've just started a class assignment, to make a simple table and I've come up with a number of errors and I can't seem to figure it out.
So, I'd like to request help, in any shape or form, Please and thank you.
My code;
#include <stdio.h>
int main(void)
char name1[William];
char name2[Geralt];
int age1 = 18;
int mark1 = 95;
int mark2 = 76;

int age2 = 17;

int average1;
average1 = (mark1 + mark2)/2;
printf("\nEnter the Student name:");
scanf("%s", &name1);

printf("| Name | Age | Mark |");
printf("| %s | %d | %d | ");
printf("| %s | %d | %d |");
printf("Average is: %d\n", average1);

return 0;

And the error i received;
exit status 1
main.c: In function 'main':
main.c:4:13: error: 'William' undeclared (first use in this function)
char name1[William];
main.c:4:13: note: each undeclared identifier is reported only once for each function it appears in
main.c:6:13: error: 'Geralt' undeclared (first use in this function)
char name2[Geralt];

Profile icon
Profile icon

These are all pretty simple mistakes. The first one I see is that you attempt to declare an array of chars by including the parentheses after the variable name. In C, you declare an array by including the parentheses after the type. Second, you need to use quotation marks to declare a string or char. So, that line should be char[] name1 = "William"; and the same goes for the line beneath it. Secondly, you will need to provide arguments to let printf() know what it's supposed to be putting in that string. The rest looks like it should be correct, but your compiler will double-check for you.
In the future, Google can be a great resource for figuring out why your compiler is yelling at you and how you should fix it.