Thread: i cant see what case is not covered..

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    i cant see what case is not covered..

    |109|warning: control reaches end of non-void function|

    i cant see what case it misses?
    Code:
    int merge_strings(char str1[], int index1,char str2[],int index2, char result[], int index3)
        {
            int answer;
    		if ((str1[index1]=='\0') && (str2[index2]=='\0'))
            {
                result[index3] = '\0';
                return 1;
            }
    		else if (((str1[index1]>='a')&&(str1[index1]<='z')) || ((str1[index1]>='A') && (str1[index1]<='Z'))
    			  && ((str2[index2]>='a')&&(str2[index2]<='z')) || ((str2[index2]>='A') && (str2[index2]<='Z'))
    			  || ((str1[index1]=='\0') || (str2[index2]=='\0')))
    			{
    			if (str2[index2]=='\0')
    				{
    					if (str1[index1]>=result[index3-1])
    					{
    						result[index3]=str1[index1];
    						answer=merge_strings(str1,index1+1,str2,index2,result,index3+1);
    						if (answer == 0)
    							return 0;
    						else
    							return 1;
    					}
    					else
    						return 0;
    				}
    			else if (str1[index1]=='\0')
    				{
    					if (str2[index2]>result[index3-1])
    					{
    						result[index3]=str2[index2];
    						answer=merge_strings(str1,index1,str2,index2+1,result,index3+1);
    						if (answer == 0)
    							return 0;
    						else
    							return 1;
    					}
    					else
    						return 0;
    				}
    			else if ((str1[index1]<=str2[index2]))
    				{
    					if (str1[index1]>=result[index3-1])
    					{
    						result[index3]=str1[index1];
    						answer=merge_strings(str1,index1+1,str2,index2,result,index3+1);
    						if (answer == 0)
    							return 0;
    						else
    							return 1;
    					}
    					 
    				}
    
    			else if ((str2[index2]<=str1[index1]))
    			{
    				if (str2[index2]>result[index3-1])
    				{
    					result[index3]=str2[index2];
                        answer=merge_strings(str1,index1,str2,index2+1,result,index3+1);
                        if (answer == 0)
    						return 0;
                        else
                            return 1;
    				}
    			}
    		}
    	else
    	{
    		return 0;   // ERROR was found  - > you return 0;
    	}
    		
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > if (str1[index1]>=result[index3-1])
    The implied else of these two fall off the end.
    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.

  3. #3
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i did an else case to that if
    i still get the same warning

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Yeah, and the one which follows it as well.

    Pretty obvious IMO if your indentation is better. I found them instantly by indenting the code properly.
    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.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    And perhaps learn to break big functions into several, and perhaps make less complicated functions, as well.
    But do you listen? Nooooo. Never.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    Quote Originally Posted by Elysia View Post
    And perhaps learn to break big functions into several, and perhaps make less complicated functions, as well.
    But do you listen? Nooooo. Never.
    i am asked to build this all in one functions

    and i dont know what to return in these else cases so it wont break the program??

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Last time I looked, you were forbidden to use external functions, not break your function into multiple ones.
    Bad:
    Code:
    void myfunc(...)
    {
        // ...
        strcpy(...);
        strcat(...);
    }
    Good:
    Code:
    void myfunc(...)
    {
        my_strcpy(...);
        my_strcat(...);
    }
    No sensible teacher would ban the ability to create one or more functions of your own for your own code.
    And you STILL need to reduce the complexity of your functions.
    And you need to learn to indent and to make flowcharts and pseudo code.
    But you won't do that, will you?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault!?!?!?
    By Viper187 in forum Windows Programming
    Replies: 57
    Last Post: 10-02-2008, 09:40 PM
  2. Format Precision & Scale
    By mattnewtoc in forum C Programming
    Replies: 1
    Last Post: 09-16-2008, 10:34 AM
  3. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  4. Creating pop up menus
    By Ti22 in forum C++ Programming
    Replies: 22
    Last Post: 01-18-2005, 09:27 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM