Thread: Hi, I currently have a problem with this error "Control reaches end of non-void func"

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    16

    Post Hi, I currently have a problem with this error "Control reaches end of non-void func"

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    #define clean while(getchar() != '\n');
    char s[36];
    
    
    void cls(){
        for(int i=0;i<50;i++)printf("\n");
    }
    void header(){
        cls();
        printf("=================================================\n");
        printf("Your current string : \"%s\"\n",s);
        printf("=================================================\n\n");
    }
    void Input(void);
    void Reverse(void);
    void Upper(void);
    void CheckAl(void);
    int CheckWo(void);
    void Split(void);
    int main(){
        int choose;
        
        cls();
        do{
            printf("Enter your first string [5..30] : ");
            scanf("%[^\n]s",&s);clean;
        }while(strlen(s) < 5 || strlen(s) > 30);
        
        
        do{
            header();
            printf("\nString Manipulator\n");
            printf("====================\n");
            printf("1. Input new string\n");
            printf("2. Reverse the string\n");
            printf("3. Uppercase the string\n");
            printf("4. Check alphaber in the string\n");
            printf("5. Checking word in the string\n");
            printf("6. Split the string\n");
            printf("7. Exit\n");
            printf("Enter your choice : ");
            scanf("%d",&choose);clean;
            
            
            switch(choose){
                case 1:
                    Input();
                    break;
                case 2:
                    Reverse();
                    break;
                case 3:
                    Upper();
                    break;
                case 4:
                    CheckAl();
                    break;
                case 5:
                    CheckWo();
                    break;
                case 6:
                    Split();
                    break;
            }
        }while(choose != 7);
        cls();
        printf("Thank you, come again ^^");getchar();
        return 0;
    }
    
    
    void Input(){
        char s1[35];
        header();
        do{
            printf("Enter the new string [5..30]: ");
            scanf("%[^\n]s",&s1);clean;
        }while(strlen(s1) < 5 || strlen(s1) > 30);
        
        strcpy(s,s1);
    }
    void Reverse(){
        header();
        printf("Reverse Successfully\n");
        printf("Enter to continue..");
        getchar();
        strrev(s);
    }
    void Upper(){
        header();
        for(int i=0;i<strlen(s);i++){
            s[i] = toupper(s[i]);
        }
        
    }
    void CheckAl(){
        header();
        printf("There are %d alphabet(s) in the string\n", strlen(s));
        printf("Enter to continue..");
        getchar();
    }
    
    
    int CheckWo(){
        header();
        char s1[11];
        do{
            printf("What word do you want to search [3..10] ? ");
            scanf("%[^\n]s", &s1);clean;
        }while(strlen(s1) < 3 || strlen(s1) > 10);
        if(strstr(s,s1)){
            printf("\"%s\" found..\n",s1);
        }else{
            printf("\"%s\" not found..\n",s1);
        }
        printf("Enter to continue..");
        getchar();
    
    
    } ( The problem exist here )
    
    
    void Split(){
        header();
        char s1[35];
        strcpy(s1,s);
        const char sep[2] = " ";
        char *temp;
        
        temp = strtok(s1, sep);
        
        int i =1;
        while( temp != NULL ) {
            printf("Word %d : %s\n",i, temp );
            
            temp = strtok(NULL, sep);
            i++;
        }
        printf("Enter to continue..");
        getchar();
    }
    Hope that you can help me

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    You have defined the function, "CheckWo()" as returning an int, but you do not return any value.

    Two options:

    1) Return a useful value from the function.
    2) Define the function as "void".

    I recommend the latter.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 08-11-2014, 09:51 AM
  2. Replies: 3
    Last Post: 07-07-2013, 01:41 AM
  3. "invalid use of void expression" error
    By smith283 in forum C Programming
    Replies: 19
    Last Post: 09-04-2012, 09:10 AM
  4. error 1421: "control ID not found"
    By JustMax in forum C Programming
    Replies: 2
    Last Post: 02-28-2009, 08:26 AM
  5. warning: control reaches end of non-void function
    By franziss in forum C Programming
    Replies: 5
    Last Post: 01-29-2005, 11:46 PM

Tags for this Thread