Thread: "warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast"

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    21

    "warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast"

    Hi, all--
    I'm writing a program to find the longest common prefix of two words (e.g. input "department" and "depart", get "depart" back; input "global" and "glossary", get "glo" back), and when I attempt to compile, I get the above warning. Here's my code, with the line in question in red:

    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
    	char one[11], two[11], prefix[11];
    	int i = 0, len;
    	printf("Please enter two words: ");
    	scanf("&#37;s%s", one, two);
    	
    	if(strlen(two) < strlen(one))
    	{
    		len = strlen(two);
    	}//if(strlen(two) > strlen(one))
    	else
    	{
    		len = strlen(one);
    	}
    
    	while(one[i]==two[i] && i < len)
    	{
    		strcat(prefix, one[i]);
    		i++;
    	}//while one[i]==two[i] -- tests each letter of one and two, and if they're the same, appends letter to prefix
    
    	printf("The longest common prefix of %s and %s is %s.", one, two, prefix);
    	return 0;
    
    }//main
    I'm not sure what I'm doing wrong or how to fix it. Any help would be greatly appreciated.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    one[i] is a single character. If you want to copy FROM position i, then you should use
    Code:
    strcat(str, &one[i]);
    --
    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.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    21
    Ah, of course! That's fixed it, thank you much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 01:09 PM
  2. assignment makes pointer from integer without a cast
    By lithium in forum C Programming
    Replies: 1
    Last Post: 04-02-2003, 11:37 PM
  3. "assignment makes integer from pointer without a cast"
    By Freez3L in forum C Programming
    Replies: 4
    Last Post: 11-04-2002, 04:26 AM
  4. assignment makes pointer from integer
    By crescen7 in forum C Programming
    Replies: 4
    Last Post: 06-25-2002, 10:08 PM
  5. Replies: 3
    Last Post: 01-14-2002, 12:13 PM