Reputation: 11
I'm trying to compile the following the program but I'm facing two errors:
#include <stdio.h>
#include <conio.h>
int main()
{
int age;
float weight;
char gender;
age = 23;
weight = 60.5;
gender = 'M ';
printf("Persons Profile \n\n\n Age: %i,\n\nweight: %f,\n\nGender: %c",age,weight,gender);
getch();
return 0;
}
Upvotes: 0
Views: 1749
Reputation: 673
The gender
variable is of type
char
.
char
in C represents the character type, suitable for storing a simple character—traditionally one from the ASCII encoding. More recently, UTF-8 encoded characters are common. The char type can also store small integers and is technically an integer type.
In your code gender
variable contains two characters M
and (space). If you remove the
space
it will remove both of your mentioned errors.
Change gender = 'M ';
To gender = 'M';
For further C assistance http://en.wikibooks.org/wiki/C_Programming
Upvotes: 2