Thread: Conflicting types???

  1. #1
    Young C n00b
    Join Date
    Jul 2006
    Posts
    59

    Conflicting types???

    Hi, i'm having trouble making the following function call:

    Code:
            char phonyArray[10][4];
            char phonyToo[4];
            makeDirs(phonyToo, phonyArray, 1);
    here is the function:

    Code:
    void makeDirs(char asg[], char exc[10][4], int numExs)
    {
            int x, t;
            for(x = 0; x < numExs; x++)
            {
                    //build sting
                    char path[10];
                    strcat(path, "./");
                    strcat(path, asg);
                    strcat(path, "/");
                    strcat(path, exc[x]);
    
                    printf("\n\n&#37;s\n\n", path);
    
    /*              t = mkdir(path,
                            //Permissions (Read, Write. Execute)
                            //for Others, User, and Group
                            S_IROTH | S_IWOTH | S_IXOTH |
                            S_IRUSR | S_IWUSR | S_IXUSR |
                            S_IRGRP | S_IWGRP | S_IXGRP);*/
            }
    }

    I'm getting an error that says i'm using incompatible types, but I don't see where i'm making this error.
    Last edited by kwikness; 10-07-2007 at 01:49 PM.

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    First of all, you're forgetting the third argument to the function.

    Anyway, try changing the function definition to:

    Code:
    void makeDirs(char *asg, char **ecs, int whatever)

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Is there a reason why you're trying to send only 2 arguments into a function that is written to accept 3?

    Edit: Too slow again.

  4. #4
    Young C n00b
    Join Date
    Jul 2006
    Posts
    59
    Sorry.. I changed that function call around after I copied and pasted and forgot to put the 1 in.. The posting now matches my code.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Most compilers will give more specific errors for "incompatible type" errors. Can you copy the exact error message?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Beautiful to C Aia's Avatar
    Join Date
    Jun 2007
    Posts
    124
    Code:
    char path[10]; /* You don't know what's in this array of chars */
    strcat(path, "./"); /* You are concatenating to it */
    What if char path[10] = "#@$%!'\0'*(1[^"; ?
    Last edited by Aia; 10-07-2007 at 05:54 PM.

  7. #7
    Young C n00b
    Join Date
    Jul 2006
    Posts
    59
    Most compilers will give more specific errors for "incompatible type" errors. Can you copy the exact error message?
    Code:
    HomeworkSetup.c:66: error: conflicting types for 'makeDirs'
    HomeworkSetup.c:59: error: previous implicit declaration of 'makeDirs' was here
    line 59 applies to the function call.
    line 66 pertains to the function definition.

    That's all the compiler gave me..

    void makeDirs(char *asg, char **ecs, int whatever)
    This also gives me the same error.


    Also tried declaring the array like this:
    Code:
    char path[10] = "\0";
    Last edited by kwikness; 10-07-2007 at 06:34 PM.

  8. #8
    Young C n00b
    Join Date
    Jul 2006
    Posts
    59
    lol.. I'm completely stumped. Clearly, there is something I'm not seeing here. Here is the entire source file:

    Code:
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <string.h>
    
    
    int main()
    {
    	FILE *ofp;
    	char asgNum[3], exercises[10][4] = {"\0"};
    	int numOfExercises;
    
    	/*
    	numOfExercises = 3;*/
    	exercises[0][0] = 'E';
    	exercises[0][1] = 'x';
    	exercises[0][2] = '0';
    	exercises[0][3] = '1';
    	/*int i;
    	for (i = 0; i <= numOfExercises; i++)
    	{
    		printf("\n&#37;c%c%c%c", exercises[i][0],
    				     exercises[i][1],
    				     exercises[i][2],
    				     exercises[i][3]);
    	}*/
    
    
    	system("clear");
    	printf("What assignment number are you doing? (Ex. P01)\n: ");
    	scanf("%s", &asgNum);
    	
    	system("clear");
    	printf("How many exercises are there?\n: ");
    	scanf("%i", &numOfExercises);
    
    	system("clear");
    	int i;
    	for(i = 0; i < numOfExercises; i++)
    	{
    		if (i == 0)
    			printf("What is the 1st Exercise number? (Ex01)\n: ");
    		else if (i == 1)
    			printf("What is the 2nd Exercise number?\n: ");
    		else if (i == 2)
    			printf("What is the 3rd Exercise number?\n: ");
    		else
    			printf("What is the %ith Exercise number?\n: ", (i+1));
    	
    		scanf("%s", exercises[i]);
    
    		system("clear");
    	}
    	
    	//printf("\n%s\n", exercises[0]);
    	
    	char phonyArray[10][4];
    	char phonyToo[4];
    	int z = 1, xx = 2, zzz = 3;
    	makeDirs(1,2,3);
    
    	return 0;
    }//end main
    
              //  asgNum   array of Excs.   num of Excercises
    //void makeDirs(char asg[4], char exc[10][4], int numExs)
    void makeDirs(int f, int g, int blah)
    {
    	int x, t;
    	for(x = 0; x < /*numExs*/g; x++)
    	{
    		//build sting
    		/*char path[10] = "\0";
    		strcat(path, "./");
    		strcat(path, asg);
    		strcat(path, "/");
    		strcat(path, exc[x]);
    
    		printf("\n\n%s\n\n", path);*/
    
    /*		t = mkdir(path,
    			//Permissions (Read, Write. Execute)
    			//for Others, User, and Group
    			S_IROTH | S_IWOTH | S_IXOTH |
    			S_IRUSR | S_IWUSR | S_IXUSR |
    			S_IRGRP | S_IWGRP | S_IXGRP);*/
    	}
    }
    
    
    
    createMakeFile(int a, char fileName[], int  asgNum, int exNum)
    {
    	FILE *ofp = fopen(fileName, "w");
    	fprintf(ofp, "#Makefile for Kyle's CIS76 Class.   #");
    	fprintf(ofp, "#Programing Assignment P%i - Exercise %i      #\n",
    		     asgNum, exNum);
    	/*fprintf(ofp, "###############################################");*/
    
    }
    /*
    #Required source files:
    #                       -Name.c
    
    #If the Name executable file is missing or if Name.c has
    #been changed, recompile
    Name : Name.c
    	cc Name.c -o Name
    
    #On clean, remove the executable file. (Usage: make clean)
    clean:
    	rm Name
    
    */

  9. #9
    Young C n00b
    Join Date
    Jul 2006
    Posts
    59
    Code:
    void makeDirs(int f, int g, int blah)
    {
    	int x, t;
    	for(x = 0; x < /*numExs*/g; x++)
    	{
    		//build sting
    		/*char path[10] = "\0";
    		strcat(path, "./");
    		strcat(path, asg);
    		strcat(path, "/");
    		strcat(path, exc[x]);
    
    		printf("\n\n%s\n\n", path);*/
    
    /*		t = mkdir(path,
    			//Permissions (Read, Write. Execute)
    			//for Others, User, and Group
    			S_IROTH | S_IWOTH | S_IXOTH |
    			S_IRUSR | S_IWUSR | S_IXUSR |
    			S_IRGRP | S_IWGRP | S_IXGRP);*/
    	}
    }
    lol wtf.. all I had to do was take the void keyword out of my function def. I thought 'void' was automatically assumed by the compiler if it didn't return anything.

  10. #10
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    lol wtf.. all I had to do was take the void keyword out of my function def. I thought 'void' was automatically assumed by the compiler if it didn't return anything.
    No, the compiler assumes "int" if you don't give a specific return value. You should always give a specific return value, though: C99 requires it, and it's good practice to be specific in any case.

    If you're using gcc, make sure to always build with the -Wall flag; it'll issue a warning about an "implicit declaration". When you use a function before you declare it, your compiler will guess that it returns int (which is why void didn't work for you) and that you're calling it properly. That is, a compiler can't check whether a function is being called correctly unless it knows what that function looks like. Thus you'll want to declare your function above main(), something like:
    Code:
    void makeDirs(int, int, int);
    int main(void) { ... }
    void makeDirs(int f, int g, int blah) { ... }
    Now the compiler knows what makeDirs() is supposed to look like when you call it. Using declarations (and more specifically what are known as prototypes, which is a function declaration with information on the types of its parameters) will help your compiler be able to tell you when things are going wrong.

  11. #11
    Young C n00b
    Join Date
    Jul 2006
    Posts
    59
    Thanks

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > exercises[0][3] = '1';
    In relation to your OTHER question, I see that none of your short strings contain a \0
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 08-23-2008, 01:16 PM
  2. error: conflicting types for 'basename'
    By samf in forum C Programming
    Replies: 3
    Last Post: 09-20-2007, 09:22 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. conflicting types for...
    By dudinka in forum C Programming
    Replies: 3
    Last Post: 05-14-2005, 07:03 AM
  5. Conflicting types of typedef error
    By advocation in forum C++ Programming
    Replies: 4
    Last Post: 03-22-2005, 06:26 PM