0

I've tried changing it to double quotes, but this is wrong, also tried figuring out what it means, but the compiler keeps giving me the same error

[Error] empty character constant
#include <stdio.h>

main()
{
    int c, i, nwhite, nother;
    int ndigit[10];
    nwhite = nother = 0;
    for(i = 0; i < 10; i++)
    ndigit[i] = 0;      

    while (( c = getchar()) != EOF)
    if( c >= '0' && c <= '9')
    ++ndigit[c - '0'];
    else if (c == '' || c == '\n' || c == '\n')
    ++nwhite;
    else 
    ++nother;

    printf("digits = ");
    for(i = 0; i < 10; i++)
        printf ("%d", ndigit[i]);
        printf(", white space = %d, other = %d \n", nwhite, nother);        
}
Swordfish
  • 12,745
  • 3
  • 19
  • 43
  • (potential) Duplicate of https://stackoverflow.com/questions/18755025/empty-character-constant-too-many-arguments-for-format-wformat-extra or https://stackoverflow.com/questions/31193454/empty-character-constant-in-c. Questions are different, but the answer is still the same as the answer for this – Tas May 20 '19 at 05:44
  • 1
    The error message is pretty obvious: Change `''` to `' '`. – Jabberwocky May 20 '19 at 05:45
  • 3
    `"[Error] empty character constant"` -- this is one of those cases where the error really does mean exactly what it says..... `:)` – David C. Rankin May 20 '19 at 06:22
  • regarding: `main()` There are only two valid signatures for `main()` (regardless of what Visual Studio might allow) They are: `int main( void )` and `int main( int argc, char *argv[] )` Notice they both have a return type of `int` – user3629249 May 20 '19 at 23:12
  • regarding: `else if (c == '' || c == '\n' || c == '\n')` This should be: `else if (c == ' ' || c == '\n' || c == '\t') // space, newline, tab` – user3629249 May 20 '19 at 23:15

1 Answers1

2

The empty character constant error is because of the following comparison in the else if clause.

c == '' //  '' is empty

Replace '' with ' '.

Swordfish
  • 12,745
  • 3
  • 19
  • 43
P.W
  • 25,639
  • 6
  • 35
  • 72