Thread: errors with basic function

  1. #1
    Registered User cDev's Avatar
    Join Date
    Jun 2006
    Posts
    26

    errors with basic function

    Hi, I'm learning about basic functions and trying to debug my code but I'm pretty sure it matches my book exactly. I've looked it over a few times and it looks ok but I'm still getting errors...so if anyone could give it another look that would be a big help. I'm compiling this on a Mac. Here's the code:

    Code:
    #include <stdio.h>
    #define MAXLINE 1000	/* maximum input line length */
    
    int getline(char line[], int max);
    int strindex(char source(), char searchfor[]);
    
    char pattern[] = "ould";	/* pattern to search for */
    
    /* find all lines matching pattern */
    main()
    {
    	char line[MAXLINE];
    	int found = 0;
    	
    	while (getline(line, MAXLINE) > 0)
    		if (strindex(line, pattern) >= 0) 
    		{
    			printf("%s", line);
    			found++;
    		}
    	return found;
    }
    
    /* getline: get line into s, return length */
    int getline(char s[], int lim)
    {
    	int c, i;
    	
    	i = 0;
    	while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
    		s[i++] = c;
    	if (c == '\n')
    		s[i++] = c;
    	s[i] = '\0';
    	return i;
    }
    
    /* strindex: return index of t in s, -1 if none */
    int strindex(char s[], char t[])
    {
    	int i, j, k;
    	
    	for (i = 0; s[i] != '\0'; i++) 
    	{
    		for (j=i, k=0; t[k]!='\0' && s[j]==t[k]; j++, k++)
    		;
    		if (k > 0 && t[k] == '\0')
    			return i;
    	}
    	return -1;
    }
    and the errors are:
    Code:
    strindex.c: In function 'main':
    strindex.c:16: warning: passing argument 1 of 'strindex' from incompatible pointer type
    strindex.c: At top level:
    strindex.c:40: error: conflicting types for 'strindex'
    strindex.c:5: error: previous declaration of 'strindex' was here
    Thanks for any help!

  2. #2
    Registered User
    Join Date
    Jun 2006
    Posts
    75
    Code:
    int strindex(char source(), char searchfor[]);
    should be

    Code:
    int strindex(char source[], char searchfor[]);

  3. #3
    Registered User cDev's Avatar
    Join Date
    Jun 2006
    Posts
    26
    lol, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post your games here...
    By Hammer in forum Game Programming
    Replies: 132
    Last Post: 02-28-2013, 09:29 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM