Mo1 Mo1 - 1 year ago 167
C Question

How to use char in C

I'm struggling to get Char to work. It keeps returning an error.

#include <stdio.h>
#include <cs50.h>
int main (void)

int tower_height;
char #;

// Inputs
do {
printf("Let's build! Give me a number between 0 and 23 'inclusive'.\n");
tower_height = GetInt();
(tower_height < 0 || tower_height > 23);

// Outputs

for (tower_height = 0; tower_height <= 23; tower_height++)
printf ("%c = tower_height - 2\n");


Answer Source

As pointed out, # is not a valid variable name. You can see how # is properly used in the first line of your code: #include <stdio.h>

Instead, call your char variable something that uses letters and numbers eg: char c;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download