Thread: Noticing a pattern of missing prototype warnings

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    4

    Noticing a pattern of missing prototype warnings

    Hi everyone. I've just begun picking up C today (with the ultimate goal of using the SDL library). As I'm moving along here, I'm beginning to notice some "missing prototype" warnings, for functions that should normally be working fine. First, the code:

    Code:
    #include <stdio.h>
    #include <string.h>
    
    /*char *lower(char upper[]) {
    	char[sizeof(upper)] duplicate;
    	for(i=0;i<sizeof(upper),i++) {
    		duplicate[i] = tolower(upper[i]);
    	}
    }*/
    
    int execFunction(char *func) {
    	printf("Executing function \"%s\"...\n", func);
    	char *lower = strlwr(func);
    	if(func == "help") {
    		system("cls");
    		printf("--+HELP+--\n\n");
    		printf("... Basically, there is no help.\nThe only function offered right now is this one.\n");
    		printf("Thanks :)");
    		getchar();
    		system("cls");
    	}
    	else {
    		printf("Sorry, that's not a function.");
    		getchar();
    		return -1;
    	}
    	return 0;
    }
    
    /* entry point */
    int main(void)
    {
    	char input[127];
    	int running = 0;
     	printf("This is teh program! Type help for commands n' stuff.");
    	gets_s(input, 127);
    	execFunction(input);
    	while(running == 0)
    	{
    		gets_s(input, 127);
    		running = execFunction(input);
    	}
        return 0;
    }
    And the errors:

    warning #2027: Missing prototype for 'strlwr'.
    error #2168: Operands of '=' have incompatible types 'char *' and 'int'.
    warning #2027: Missing prototype for 'system'.
    warning #2027: Missing prototype for 'gets_s'.
    (Don't worry about that error, I'll worry about it later.)

    Anyhow, as you can see, it seems some of the most basic functions are being taken as missing prototypes. What am I doing wrong here?

    Thanks in advance.

    ~TGP1994

  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
    Well you're better off using the standard fgets() rather than the non-portable gets_s

    And system is in stdlib.h

    As for the other one, I've no idea - it could be anything, anywhere (it isn't standard)
    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
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You don't have anything called "strlwr". You have something called "lower".
    Since you don't have anything prototyped for "strlwr", it assumes it returns an int.
    You don't have "system" prototyped, or rather, you haven't included stdlib.h.

    Edit: Curses, foiled again!


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Aug 2010
    Posts
    4
    Excellent, thank you guys. In case anyone is curious, here is my fixed code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    char lower(char upper[]) {
    	char duplicate[sizeof(upper)];
    	int i = 0;
    	for(i=0;i<sizeof(upper);i++) {
    		duplicate[i] = tolower(upper[i]);
    	}
    	return * duplicate;
    }
    
    int execFunction(char *func) {
    	printf("Executing function \"%s\"...\n", func);
    	char lwr = lower(func);
    	if(func == "help") {
    		system("cls");
    		printf("--+HELP+--\n\n");
    		printf("... Basically, there is no help.\nThe only function offered right now is this one.\n");
    		printf("Thanks :)");
    		getchar();
    		system("cls");
    	}
    	else {
    		printf("Sorry, that's not a function.");
    		getchar();
    		return -1;
    	}
    	return 0;
    }
    
    /* entry point */
    int main(void)
    {
    	char input[127];
    	int running = 0;
     	printf("This is teh program! Type help for commands n' stuff.");
    	gets(input);
    	execFunction(input);
    	while(running == 0)
    	{
    		gets(input);
    		running = execFunction(input);
    	}
        return 0;
    }

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'm not sure why you have "lower" returning anything, since you never use it. Also, you cannot compare strings with ==, you will need something like strcmp in string.h instead. Finally, you should avoid gets. There's a FAQ on it.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Aug 2010
    Posts
    4
    Quote Originally Posted by quzah View Post
    I'm not sure why you have "lower" returning anything, since you never use it.
    Code:
    int execFunction(char *func) {
    	printf("Executing function \"%s\"...\n", func);
    	char lwr = lower(func);
    Alright, I'll check out the FAQ for gets.

    Thanks!

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The code is fundamentally broken. It's not fixed... yet.
    >>char duplicate[sizeof(upper)];
    Since upper is an argument, this is the size of a pointer. Always. Not what you want.
    It should be strlen(input) + 1.

    Also, as noted, you cannot compare strings with ==. You must use strcmp.
    And gets is the devil's tool. Here's an explanation of why: SourceForge.net: Gets - cpwiki

    And quzah is right. lwr is not used anywhere, so it's unnecessary.
    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.

  8. #8
    Registered User
    Join Date
    Aug 2010
    Posts
    4
    Quote Originally Posted by Elysia View Post
    The code is fundamentally broken. It's not fixed... yet.
    >>char duplicate[sizeof(upper)];
    Since upper is an argument, this is the size of a pointer. Always. Not what you want.
    It should be strlen(input) + 1.

    Also, as noted, you cannot compare strings with ==. You must use strcmp.
    And gets is the devil's tool. Here's an explanation of why: SourceForge.net: Gets - cpwiki

    And quzah is right. lwr is not used anywhere, so it's unnecessary.
    Ah, I see what he was talking about now for lwr not being used. Looks like I just forgot to use the correct variable later. And yup, I'm using fgets now.

    Anyhow, it seems I'm not defining lwr correctly, since I'm receiving this; "Illegal initialization of variable-length array 'lwr'." (Originally, it was complaining about attempting to compare argument 1 in strcmp, expecting a const char *, but receiving a char, so I think I have to initialize lwr as an array.)

    Here's what that block of code looks like:
    Code:
    int execFunction(char *func) {
    	printf("Executing function \"%s\"...\n", func);
    	char lwr[sizeof(func)] = lower(func);
    Although it seems like sizeof() should be returning a datatype that's very close to int. (I'm reading up on an a topic about that as we speak.)

    (Later)
    Ah, so it's giving me the physical size of the pointer, rather than what it's pointing too? It seems like I can't use strlen in this case.
    Last edited by tgp1994; 08-04-2010 at 02:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 03:01 PM
  2. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM