error when compiling if statement

This is a discussion on error when compiling if statement within the C Programming forums, part of the General Programming Boards category; I keep getting a syntax error when trying to compile an if statement: Code: #include <stdio.h> #include <conio.h> char c; ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    76

    error when compiling if statement

    I keep getting a syntax error when trying to compile an if statement:
    Code:
    #include <stdio.h> 
    #include <conio.h> 
    char c; 
    int main (void) 
     
    { 
     
    printf("press any key"); 
    c = getch(); 
     
    if (iscntrl (c))    /* ...... Error is here ................ */
     
     
     
     
     
    printf(" you entered a control character",c); 
     
     
     
    }

  2. #2
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Code:
    printf(" you entered a control character",c);
    Your error is in this line. Why do you have a second argument?

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Your error is in this line. Why do you have a second argument?
    The C standard guarantees that extra arguments to printf are ignored, so that's not an error. It is, however, a mistake.

    >if (iscntrl (c)) /* ...... Error is here ................ */
    You need to include <ctype.h> if you want to use iscntrl().
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. If Else statement problem
    By doofusboy in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 06:18 AM
  4. string & if statement
    By Curacao in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 09:56 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 03:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21