Not booting error

1

I'm having a non-boot error, and I can not figure out why:

#include <stdio.h>
int main(){
  const int LENGTH = 10;
  const int WIDTH = 5;
  const char NEWLINE = "\n";
  int area;
  area = LENGHT * WIDTH;
  printf("Value of area : %d", area);
  printf("%c", NEWLINE);
  return 0;
}

Errors:

C:\Users\zegla\OneDrive\Ambiente de Trabalho\Cexs\trainning6_const.c: In function 'main':
C:\Users\zegla\OneDrive\Ambiente de Trabalho\Cexs\trainning6_const.c:6:24: warning: initialization makes integer from pointer without a cast [-Wint-conversion]
   const char NEWLINE = "\n";
                        ^
C:\Users\zegla\OneDrive\Ambiente de Trabalho\Cexs\trainning6_const.c:9:10: error: 'LENGHT' undeclared (first use in this function)
   area = LENGHT * WIDTH;
          ^
C:\Users\zegla\OneDrive\Ambiente de Trabalho\Cexs\trainning6_const.c:9:10: note: each undeclared identifier is reported only once for each function it appears in
    
asked by anonymous 12.12.2017 / 21:51

1 answer

2

There are two errors, one is typing, the LENGTH variable is spelled wrong.

The other error is that you are trying to save an address to a string in a variable that is not a string . It would need to be a pointer to support what you want.

#include <stdio.h>

int main(){
    const int LENGTH = 10;
    const int WIDTH = 5;
    const char *NEWLINE = "\n";
    int area;
    area = LENGTH * WIDTH;
    printf("Value of area : %d", area);
    printf("%c", NEWLINE);
    return 0;
}

See running on ideone . And no Coding Ground . Also I put it in GitHub for future reference .

In online IDEs I've done a little better and different in each case.

This is not usually done, although this code is unnecessary, so it is even difficult to say what could be better, since it would be better to do everything differently. You may end up getting addicted to doing programming this way. This code produces the same result with a line.

    
12.12.2017 / 22:00