Thread: parameter names without types and conflicting types in fgets

  1. #1
    Registered User
    Join Date
    Jan 2014
    Posts
    4

    Question parameter names without types and conflicting types in fgets

    I have this code:
    Code:
    #include<stdio.h>
    #include<ctype.h>
    #include<string.h>
    
    
    int check_up(char string[]);
    int check_low(char string[]);
    void to_up(char string[]);
    void to_low(char string[]);
    
    
    int main()
    {    char word[1];
        printf("Input a string:");
        fgets(word, sizeof(word), stdin);
        int up, low;
        
        up= check_up(word);
        low= check_low(word);
            
        if( (up==0) && (low ==0)){
            printf("%s is neither all uppercase nor all lowercase.\n", word);        
        }else if( low==1){
            printf("%s is all lowercase.\n", word);
        }else if( up==1)
            printf("%s is all uppercase.\n", word);
        }
        
        to_up(word);
        printf("All uppercase %s.\n", word);
        to_low(word);
        printf("All lowercase %s.\n", word);
        
        return 0;
    }
    //Check if all upper
    int allupper(char string[]){
        int a;
        a = 0;
        if ( string[a] == '\n' )
            {
                string[a] = '\0'; 
            }    
        isupper(string[a]);
    }
    //Check if all lower
    int alllower(char string[]){
        int a;
        a = 0;
        if ( string[a] == '\n' )
            {
                string[a] = '\0'; 
            }    
        islower(string[a]);
    }
    //Converts to lower
    void to_low(char string[]){ 
        int a;
        a = 0;
        if ( string[a] == '\n' )
            {
                string[a] = '\0'; 
            }
         string[a] = tolower(string[a]);
    }
    //Converts to upper
    void to_up(char string[]) {    
        int a;
             a = 0;
        if ( string[a] == '\n' )
            {
                string[a] = '\0'; 
            }
        string[a] = tolower(string[a]);
    }
    When I compile this I have the following problems:
    • warning: data definition has no type or storage class [enabled by default] in 'to_up(word)'
    • conflicting types in 'to_up' function and to_low function
    • warning: data definition has no type or storage class [enabled by default] into_up function
    • error: unknown type name ‘word’ in line 'printf("All uppercase %s.\n", word):;'
    • warning: parameter names (without types) in function declaration [enabled by default] in 'to_up(word)'and 'to_low(word)'
    • 'note: previous declaration of ‘to_up’ was here in function declaration of to_up function

    How I can fix this problems?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You have a close-curly-brace on line 27 (of what's posted here) that doesn't match any open-curly-brace. (Or more to the point, as far as the compiler is concerned it matches the open curly brace on line 13, which means you have a lot of code that no longer lives in a function.)
    Using actual indentation, and better yet, watching when your editor indents things in a way that doesn't match what you want, would really help you spot this sort of thing.

  3. #3
    Registered User
    Join Date
    Jan 2014
    Posts
    4
    You have a close-curly-brace on line 27 (of what's posted here) that doesn't match any open-curly-brace. (Or more to the point, as far as the compiler is concerned it matches the open curly brace on line 13, which

    Thanks
    But what does this mean
    warning: statement with no effect [-Wunused-value] in 54 and 44?
    Last edited by korisu48; 01-22-2014 at 07:59 AM.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Assuming the line numbers haven't changed, then line 44 is
    Code:
     isupper(string[a]);
    which is exactly what the warning says: a statement with no effect. isupper just returns true/false. If you want to do something with that information, then ... well, you should do something with it as opposed to currently, where you are just having it sit there and not do anything.

  5. #5
    Registered User
    Join Date
    Jan 2014
    Posts
    4
    Code:
    return isupper(string[a]);
    return isupper(string[a]);
    Changed
    Code:
    char size[2];
    now accepts input but if input is pizza output is:
    Input a string: pizza
    All uppercase p.
    All lowercase p.
    Last edited by korisu48; 01-22-2014 at 08:34 AM.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well, a two-byte string can hold exactly one letter in it (one byte is reserved for the end-of-string marker). If you want more letters, you need a bigger string.

    Also, none of your functions work with anything other than the first letter -- you are always starting with a = 0, but it never changes as you go. You probably want loops.

  7. #7
    Registered User
    Join Date
    Jan 2014
    Posts
    4
    Code:
    if( (up==0) && (low ==0)){
    		printf("%s is neither all uppercase nor all lowercase.\n", word);		
    	}else if( low==1){
    		printf("%s is all lowercase.\n", word);
    	}else if( up==1){
    		printf("%s is all uppercase.\n", word);
    	}
    
    int check_up(char string[]){
    	int a,b;
    	a = 0;
    	while( (string[a] != '\0') && (string[a] != '\n'))
            {	b= isupper(string[a]);
    			a++;			
    			if(a>SIZE)
    				break;
            }
    	if(b != 0)
    		b=1;	
    	return b;
    If my input is NMB48 it is supposed to display that NMB48 is uppercase, but it says it is neither.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Why should NMB48 be all uppercase? Neither 4 nor 8 is an uppercase letter.

    (If you want to exclude non-letters, then you need to check isalpha before you check isupper.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. conflicting types
    By Sotiris Kaniras in forum C Programming
    Replies: 27
    Last Post: 01-01-2013, 09:18 AM
  2. parameter names (without types) in function declaration
    By brightmatter in forum C Programming
    Replies: 1
    Last Post: 04-15-2010, 07:09 PM
  3. Conflicting types???
    By kwikness in forum C Programming
    Replies: 11
    Last Post: 10-07-2007, 11:53 PM
  4. error: conflicting types
    By Rodman in forum C Programming
    Replies: 5
    Last Post: 03-10-2006, 04:20 AM
  5. conflicting types for...
    By dudinka in forum C Programming
    Replies: 3
    Last Post: 05-14-2005, 07:03 AM

Tags for this Thread