Function for chek if letter exist

This is a discussion on Function for chek if letter exist within the C Programming forums, part of the General Programming Boards category; Hi ,I wrote this functiont to check for abanded characters ,but it doesnt work I need help Thanks The errors ...

  1. #1
    lio
    lio is offline
    Registered User
    Join Date
    Nov 2010
    Posts
    47

    Function for chek if letter exist

    Hi ,I wrote this functiont to check for abanded characters ,but it doesnt work
    I need help
    Thanks
    The errors are missing terminating characters
    Code:
    int checkout(char letter)
    {
      char forbiden[20]={'{','}','[',']','(',')','0','1','2','3','4','5','6','7','8','9','+,'-','*','/'};
      int i;
      int numErrors=0;
      for(i=0;i<20;i++)
      {
        if(forbiden[i]!=letter);
        numErrors++;
      }
      return numErrors;
    }
    Last edited by lio; 01-18-2011 at 12:32 PM.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Try it like this....

    Quote Originally Posted by lio View Post
    Code:
    int checkout(char letter)
    {
      char forbiden[21]={"{}[]()0123456789+-*/\0"};
      int i;
      int numErrors=0;
      for(i=0;i<20;i++ )  
       {
        if(forbiden[i] == letter)
        numErrors++;
      }
      return numErrors;
    }

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    It doesn't work, because it doesn't compile - your if statement is broken.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    lio
    lio is offline
    Registered User
    Join Date
    Nov 2010
    Posts
    47
    Thanks,
    Common tater
    I pasted your code agin and it works
    Last edited by lio; 01-18-2011 at 12:42 PM.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    It's no use saying "an error", you need to post actual error messages.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by lio View Post
    Thanks,
    Common tater
    I pasted your code agin and it works
    Now... do yourself the favor of spending a minute and figuring out WHY it works...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 06:05 PM

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