syntax error at the end of input.. and warning (multi-character constant) help!

This is a discussion on syntax error at the end of input.. and warning (multi-character constant) help! within the C Programming forums, part of the General Programming Boards category; I don't know how to fix this. Here's my code. The error's at the last line. Code: #include <stdio.h> #include ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    33

    syntax error at the end of input.. and warning (multi-character constant) help!

    I don't know how to fix this.

    Here's my code. The error's at the last line.

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    #define max_con 30
    
    void add_contact();
    void edit_contact();
    void del_contact();
    void list_contact();
    
    char addressbook[5][30][30];
    char mode;
    int address_count = 0, current_record = 0;
    
    int main(void)
    {    
        do
        {
        printf("Welcome: This is an address book program brought to you by\nJohn Ranniel G. Sison\n");
        
        printf("Select the mode you want\n");
        printf("1 -> Add contact\n"); 
        printf("2 -> Edit contact\n");
        printf("3 -> Delete contact\n");
        printf("4 -> List contact\n");
        printf("5 -> Exit the program\n");
        scanf("%c", &mode);
        
            switch(mode){ //switch (determine which action to take)
        
            case '1':
            add_contact();
            break;
            case '2':
            edit_contact();
            break;
            case '3':
            del_contact();
            break;
            case '4':
            list_contact();
            break;
            case '5':
            return 0;
            default:
                while(mode<5&&mode>=1)
                printf("Please choose from the given options.\n");
                scanf("%c", &mode);
            } 
        } 
        while(mode != '5');
         
         
    }
    
    void add_contact()
    {
        char entry[30];
        int i, length, flag;
        if(mode=='1')
            if (address_count == max_con){ //checks if the number of contacts is has not yet reached the maximum which is max_con
            printf("Sorry, the %d entry limit has been reached.\nChoose other functions other than '1'", max_con);
            return;
            }
            else {
            address_count++; //variable for number of entries
            current_record = address_count-1; //variable for the current entry
            length = strlen(addressbook[0][current_record]);
           
       //asks the user to input the entry's first name (Alphabet, spaces) and it must not exceed 20 characters    
        do
        {
            printf("Enter the first name:"); //asks the user to input the first name of the entry
            scanf("%s", addressbook[0][current_record]);
            length = strlen(addressbook[0][current_record]); //gets the length of the input (should be less than 20)
                for(i=0; i<=20; i++)
                {
                    if(isalpha((addressbook[0][current_record][i])||addressbook[0][current_record][i]==' ')&&length<20)
                    { //checks if the input characters in first name are alphabets/a space and strlen is less than 20
                        flag = 1;
                        break; //
                    } //exits once it sees that the characters are alpha numeric
                    else 
                    {
                        printf("You can only use alphabets and space and a maximum of 20 characters. First name?\n"); //puts a message that prompts the user to enter alphabets/space alone
                        break;
                    }  
                } 
        } 
        while(flag!=1);
            
      //asks the user to input the surname of the entry (Alphabet, spaces) and it must not exceed 20 characters
        flag = 0;
        do
        {
            printf("Enter the surname:"); //
            scanf("%s", addressbook[1][current_record]);
            length = strlen(addressbook[1][current_record]); //gets the length of the input (should be less than 20)
                for(i=0; i<=20; i++){
                    if(isalpha((addressbook[1][current_record][i])||addressbook[1][current_record][i]==' ')&&length<20)
                    { //checks if the input characters in surname are alphabets/a space and strlen is less than 20
                        flag = 1;
                        break; //
                    } //exits once it sees that the characters are alpha numeric
                    else 
                    {
                        printf("You can only use alphabets and space and a maximum of 20 characters. First name?\n"); //puts a message that prompts the user to enter alphabets/space alone
                        break;
                    }    
                } 
        } 
        while(flag!=1); 
        
        //asks the user to input the degree program of the entry(Alphabet, spaces) and it must not exceed 20 characters
        flag = 0;
        do{
            printf("Enter the Degree Program the entry's in:"); 
            scanf("%s", addressbook[2][current_record]);  
            length = strlen(addressbook[2][current_record]); //gets the length of the input (should be less than 20)
                for(i=0; i<=20; i++)
                {
                    if(isalpha((addressbook[2][current_record][i])||addressbook[2][current_record][i]==' ')&&length<20)
                    { //checks if the input characters in the degree program are alphabets/a space and strlen is less than 20
                        flag = 1;
                        break; 
                    } //exits once it sees that the characters are alpha numeric
                    else 
                    {
                        printf("You can only use alphabets and space and a maximum of 20 characters. First name?\n"); //puts a message that prompts the user to enter alphabets/space alone
                        break;
                    } 
                } 
        } 
        
        while(flag!=1);
        flag = 0;
        do
        {
            printf("Enter the entry's Student ID:");
            scanf("%s", addressbook[3][current_record]);
            length = strlen(addressbook[3][current_record]); //gets the length of the input (should be 10)
            addressbook[3][current_record];
                for(i=0; i<10; i++)
                {
                    if((addressbook[3][current_record][i]>='0')&&(addressbook[3][current_record][i]<'4')||(addressbook[3][current_record][i]>'4')&&(addressbook[3][current_record][i]<=9))
                      //checks if the input characters are only numbers and the 4th element of the array is a '-' 
                    if((addressbook[3][current_record][4]=='-')&&(strlen(addressbook[3][current_record])=='10'))
                    { //checks if the input characters are only numbers and the 4th element of the array is a '-' 
                        flag = 1;
                        break;
                    }
                    else 
                    { //prints restrictions/parameters for the student ID
                        printf("The format of your input should be like this:\nxxxx-yyyyy\nWhere: the x's and y's represent ONLY numbers");
                        break; 
                    } 
                } 
        }
        while(flag!=1);
        
        flag = 0;
        do
        { 
        printf("Enter the entry's cellphone number:");
            scanf("%s", addressbook[4][current_record]);
            length = strlen(addressbook[4][current_record]); //gets the length of the input (should be 10)
            //checks if the input is composed of 11 elements wherein the first 2 are 0 and 9 respectively
                for(i=0; i<11; i++){
                    if((addressbook[4][current_record][0] == '0')&&addressbook[4][current_record][1] == '9'||(addressbook[4][current_record][i]>='0')&&(addressbook[4][current_record][i]<='9')&&(length)=='11')
                    {   
                        flag = 1;
                        break;
                    }
                    else 
                    { //prints restrictions/parameters for the cellphone number
                        printf("The format of the input is: 09xxyyyyyyy\nwherein x and y are integers from 0 -> 9\n");
                        break; 
                    } 
            } 
        } 
        while(flag!=1);
        
        flag = 0;
        do  
        {
            printf("Enter the entry's email address:");
            scanf("%s", addressbook[5][current_record]);
            length = strlen(addressbook[5][current_record]); //gets the length of the input (should be 10)
            //checks if input is composed of letters//digits/underscores/dots/@ &max of 30 characters
                for(i=0; i<30; i++){
                    if((addressbook[5][current_record][i]>='A')&&(addressbook[5][current_record][i]<='z')||(addressbook[5][current_record][i]=='.')||
                    (addressbook[5][current_record][i]=='@')||(addressbook[5][current_record][i]=='_')||(addressbook[5][current_record][i]>='0')&&(addressbook[5][current_record][i]<='9')&&length<=30)
                  {
                       flag = 1;
                       break;
                  }
                
                    else 
                    { //prints restrictions/parameters for the cellphone number
                        printf("The email address entry can only be composed of letters, numbers, '.', '_' and '@' \n");
                        break; 
                    } 
            } 
        } 
        
        while(flag!=1);
          
    } //end add_contact function
    
    void edit_contact()
    {
        char i, j, k, flag, length;
        int num;
        
        printf("Edit which entry?\n");
        printf("------------------\n");
        printf("Enter the number of the entry you want to edit:");
        scanf("%d", &num);
        //edits first name of entry
        do
        {
            printf("Edit the first name:"); //asks the user to input the first name of the entry
            scanf("%s", addressbook[0][num]);
            length = strlen(addressbook[0][num]); //gets the length of the input (should be less than 20)
                for(i=0; i<=20; i++)
                {
                    if(isalpha((addressbook[0][num][i])||addressbook[0][num][i]==' ')&&length<20)
                    { //checks if the input characters in first name are alphabets/a space and strlen is less than 20
                        flag = 1;
                        break; 
                    } //exits once it sees that the characters are alpha numeric
                    else 
                    {
                        printf("You can only use alphabets and space and a maximum of 20 characters. First name?\n"); //puts a message that prompts the user to enter alphabets/space alone
                        break;
                    } //end else    
                } 
        } 
        while(flag!=1);
      //edits surname
      //asks the user to input the surname of the entry (Alphabet, spaces) and it must not exceed 20 characters
        flag = 0;
        do
        {
            printf("Edit the surname:"); //
            scanf("%s", addressbook[1][num]);
            length = strlen(addressbook[1][num]); //gets the length of the input (should be less than 20)
                for(i=0; i<=20; i++)
                {
                    if(isalpha((addressbook[1][num][i])||addressbook[1][num][i]==' ')&&length<20)
                    { //checks if the input characters in surname are alphabets/a space and strlen is less than 20
                        flag = 1;
                        break; //
                    } //exits once it sees that the characters are alpha numeric
                    else 
                    {
                        printf("You can only use alphabets and space and a maximum of 20 characters. First name?\n"); //puts a message that prompts the user to enter alphabets/space alone
                        break;
                        } //end else    
                } // end for
        } //end do
        while(flag!=1); 
        //edits the course
        //asks the user to input the degree program of the entry(Alphabet, spaces) and it must not exceed 20 characters
        do{
            printf("Enter the Degree Program the entry's in:"); 
            scanf("%s", addressbook[2][num]);  
            length = strlen(addressbook[2][num]); //gets the length of the input (should be less than 20)
                for(i=0; i<=20; i++){
                    if(isalpha((addressbook[2][num][i])||addressbook[2][num][i]==' ')&&length<20)
                    { //checks if the input characters in the degree program are alphabets/a space and strlen is less than 20
                        flag = 1;
                    break; //
                    } //exits once it sees that the characters are alpha numeric
                    else {
                    printf("You can only use alphabets and space and a maximum of 20 characters. First name?\n"); //puts a message that prompts the user to enter alphabets/space alone
                    break;} //end else    
                } // end for
        } //end do
        
        while(flag!=1);
        // edits student ID of entrynumber
        flag = 0;
        do{
            printf("Edit the entry's Student ID:");
            scanf("%s", addressbook[3][num]);
            length = strlen(addressbook[3][num]); //gets the length of the input (should be 10)
            addressbook[3][current_record];
                for(i=0; i<10; i++){
                    if((addressbook[3][num][i]>='0')&&(addressbook[3][num][i]<'4')||(addressbook[3][num][i]>'4')&&(addressbook[3][num][i]<=9))
                      //checks if the input characters are only numbers and the 4th element of the array is a '-' 
                    if((addressbook[3][num][4]=='-')&&(strlen(addressbook[3][num])=='10'))
                    { //checks if the input characters are only numbers and the 4th element of the array is a '-' 
                        flag = 1;
                    break;
                    }
                    else { //prints restrictions/parameters for the student ID
                    printf("The format of your input should be like this:\nxxxx-yyyyy\nWhere: the x's and y's represent ONLY numbers");
                    break; } //end else
            } //end for
        } // end do
        while(flag!=1);
       //edit cellphone number
        flag = 0; 
        do
        { 
        printf("Edit the entry's cellphone number:");
            scanf("%s", addressbook[4][num]);
            length = strlen(addressbook[4][num]); //gets the length of the input (should be 10)
            //checks if the input is composed of 11 elements wherein the first 2 are 0 and 9 respectively
                for(i=0; i<11; i++){
                    if ((addressbook[4][num][0] == '0') && (addressbook[4][num][1] == '9') || (addressbook[4][num][i]>='0') && (addressbook[4][num][i]<='9'))
                    {
                        if(length == 11){
                            flag = 1;
                            break;                        
                        }
                    }
                 
                    else { //prints restrictions/parameters for the cellphone number
                    printf("The format of the input is: 09xxyyyyyyy\nwherein x and y are integers from 0 -> 9\n");
                    break; } //end else
            } //end for
        } // end do
        while(flag!=1); 
        
       //edit email address 
        flag = 0;
        do
        { 
        printf("Enter the entry's email address:");
            scanf("%s", addressbook[5][num]);
            length = strlen(addressbook[5][num]); 
            
            //checks if input is composed of letters//digits/underscores/dots/@ &max of 30 characters
                for(i=0; i<30; i++){
                if((addressbook[5][num][i]>='A')&&(addressbook[5][num][i]<='z')||(addressbook[5][num][i]=='.')||
                (addressbook[5][num][i]=='@')||(addressbook[5][num][i]=='_')||(addressbook[5][num][i]>='0')||(addressbook[5][num][i]<='9')&&length<=30){
                       flag = 1;
                    break;
                    }
                //prints restrictions/parameters for the cellphone number
                    else { 
                    printf("The email address entry can only be composed of letters, numbers, '.', '_' and '@' \n");
                    break; } 
            } 
        } 
        while(flag!=1);     
    } 
    
    void del_contact()
    { 
       int del, i;
       
       printf("Enter the number of entry/contact you want to delete.\n");
       printf("Contact number:");
       scanf("%d", &del);
       
       //for loop to assign '/0' as the content for the given entry
           for(i=0; i<6; i++)
           {
                strcpy(addressbook[i][del], addressbook[6][0]);
           }
        //after deletion of the contents of the entries, address_count and current_record are both reset to 0 
        address_count = 0;
        current_record = 0;
    } //end delete function

  2. #2
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    A lot more than just that error. Many non-trivial warnings:
    Code:
    contact2.c: In function 'add_contact':
    contact2.c:142: warning: statement with no effect
    contact2.c:145: warning: suggest parentheses around '&&' within '||'
    contact2.c:147:103: warning: multi-character character constant
    contact2.c:145: warning: suggest explicit braces to avoid ambiguous 'else'
    contact2.c:169:200: warning: multi-character character constant
    contact2.c:169: warning: suggest parentheses around '&&' within '||'
    contact2.c:191: warning: suggest parentheses around '&&' within '||'
    contact2.c:192: warning: suggest parentheses around '&&' within '||'
    contact2.c:60: warning: suggest explicit braces to avoid ambiguous 'else'
    contact2.c: In function 'edit_contact':
    contact2.c:227: warning: array subscript has type 'char'
    contact2.c:227: warning: array subscript has type 'char'
    contact2.c:250: warning: array subscript has type 'char'
    contact2.c:250: warning: array subscript has type 'char'
    contact2.c:270: warning: array subscript has type 'char'
    contact2.c:270: warning: array subscript has type 'char'
    contact2.c:288: warning: statement with no effect
    contact2.c:290: warning: array subscript has type 'char'
    contact2.c:290: warning: array subscript has type 'char'
    contact2.c:290: warning: array subscript has type 'char'
    contact2.c:290: warning: array subscript has type 'char'
    contact2.c:290: warning: suggest parentheses around '&&' within '||'
    contact2.c:292:81: warning: multi-character character constant
    contact2.c:290: warning: suggest explicit braces to avoid ambiguous 'else'
    contact2.c:312: warning: array subscript has type 'char'
    contact2.c:312: warning: array subscript has type 'char'
    contact2.c:312: warning: suggest parentheses around '&&' within '||'
    contact2.c:337: warning: array subscript has type 'char'
    contact2.c:337: warning: array subscript has type 'char'
    contact2.c:337: warning: array subscript has type 'char'
    contact2.c:337: warning: suggest parentheses around '&&' within '||'
    contact2.c:338: warning: array subscript has type 'char'
    contact2.c:338: warning: array subscript has type 'char'
    contact2.c:338: warning: array subscript has type 'char'
    contact2.c:338: warning: array subscript has type 'char'
    contact2.c:338: warning: suggest parentheses around '&&' within '||'
    contact2.c:212: warning: unused variable 'k'
    contact2.c:212: warning: unused variable 'j'
    contact2.c: In function 'add_contact':
    contact2.c:367: error: expected declaration or statement at end of input
    contact2.c:58: warning: unused variable 'entry'

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    33
    Oh what should I do? I use a Dev-C++ compiler and there's just one error. And 3 multi character warnings.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    2,553
    Quote Originally Posted by johnjrgs View Post
    Oh what should I do? I use a Dev-C++ compiler and there's just one error. And 3 multi character warnings.
    My guess find out where you are missing a closing brace "}".

    "contact2.c: In function 'add_contact':" This implies you are missing a brace in this function "add_contact"

    Edit: Most of the other warnings (from Tclausex) are from using a newer version of GCC as the compiler.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    2,553
    Code:
    if (condition){
      ;
    } else {
      ;
    } // end if
    I suggest using an auto code format program and/or adding comments to you closing braces like in the posted code snippet.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    A development process
    Have you compiled (or run) the code at all, before it got to well over 300 lines long?

    If your comfort zone is write 10 lines, compile and can fix whatever happens, then do that.

    But writing 100 lines, compile and be hopelessly lost is not productive.
    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.

  7. #7
    Registered User
    Join Date
    Feb 2013
    Posts
    33
    Thanks for the help Tim S! Code's working now! I'll just try to fix the remaining errors in the code. Hehe, really a big help

    I also want to ask though what parameters are needed to check a string if it is an alphabet(lower/upper) and string is at most 20 (length)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multi-character character constant warning
    By visuthan in forum C Programming
    Replies: 3
    Last Post: 07-16-2012, 12:43 PM
  2. Multi Character Constant.. how to correct the error? 3:
    By Tinray Reyes in forum C++ Programming
    Replies: 2
    Last Post: 06-04-2011, 08:30 AM
  3. warning: multi-character character constant
    By aadil7 in forum C Programming
    Replies: 2
    Last Post: 12-12-2010, 09:02 PM
  4. "warning: multi-line character constant"
    By Benzakhar in forum C++ Programming
    Replies: 7
    Last Post: 08-24-2008, 03:29 PM
  5. multi-character character constant error
    By robwhit in forum C Programming
    Replies: 3
    Last Post: 07-15-2007, 12:12 AM

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