parse error

This is a discussion on parse error within the C Programming forums, part of the General Programming Boards category; Im getting an error and i dont know what i need to do to fix it. Also can anyone let ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    51

    parse error

    Im getting an error and i dont know what i need to do to fix it. Also can anyone let me know if im doing the right thing here. I want my program to read from input either numbers or words and convert them to the oposite and print to output. Ive begun here with entering numbers and printing out the corresponding word.

    Code:
    #include <stdio.h>
    
       int one(char *cmd);
       void two();
       char buff[BUFSIZ];
    
               
       int main(){
               
          printf("If you wish to enter a numeral enter 'n', or if you wish to enter a word enter 'w'. \n");
          char buff[BUFSIZ];
          while ( fgets( buff, BUFSIZ, stdin ) != NULL ) {
             switch ( buff[0] ) {
                case 'n':
                   one ( buff );
                   return 0;
                default: printf("error");
                   return 0;
             }
          }
       }
    
               
       int one(char *cmd){
               
          int numeral;
    int res;
          res = sscanf( cmd, "%*c %d", &numeral ); 
     
          switch(numeral){
             case 0: printf("zero \n");
                break;
             case 1: printf("one \n");
                break;
             case 2: printf("two \n");
                break;
             case 3: printf("three \n");
                break;
             case 4: printf("four \n");
                break;
             case 5: printf("five \n");
                break;
             case 6: printf("six \n");
                break;
             case 7: printf("seven \n");
                break;
             case 8: printf("eight \n");
                break;
             case 9: printf("nine \n");
                break;
             case 10: printf("ten \n");
                break;
             case 11: printf("eleven \n");
                break;
             case 12: printf("twelve \n");
                break;
             case 13: printf("thirteen \n");
                break;
             case 14: printf("fourteen \n");
                break;
             case 15: printf("fifteen \n");
                break;
             case 16: printf("sixteen \n");
                break;
             case 17: printf("seventeen \n");
                break;
             case 18: printf("eighteen \n");
                break;
             case 19: printf("ninteen \n");
                break;
             default: printf("error \n");
                break;
          }
       }

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    51
    In regards to the user inputting words, how do i go about that, should i use strstr or what?

    Code:
       int two(){
               
          char word;
       
          scanf("%s", &word ); 
          switch(word){
             case 'zero': printf("0 \n");
                break;
             case 'one': printf("1 \n");
                break;

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    51
    I dont have a book yet, i have one on order and im waiting for it to arrive.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You already have the buffer declared in global scope, so why are you redefining it in main?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 03:39 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

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