Thread: Function prototypes

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    12

    Post Function prototypes

    Hi, this is my first post on this site, so hopefully this is correct way of doing things.
    I have started typing a piece of code that allows input of two strings that will be placed together. However i have come across this error : "'mystrcat' : cannot convert parameter 1 from 'char [80]' to 'char'" and cant figure out how to correct it.
    Any help appreciated.

    Code:
    #include "stdafx.h"
    #include "ctype.h"
    #include "string.h"
    
    char mystrcat(char, char);
    
    int main()
    {
    	char string1[80], string2[80];
    	for (;;)
    	{
    		printf("Enter string1: ");
    		scanf("%s", &string1);
    		if (!strcmp(string1, "done"))
    			break;
    		printf("Enter string2: ");
    		scanf("%s", &string2);
    		printf("String1: %s String2: %s\n", string1, string2);
    		printf("Returned string : %s\n", mystrcat(string1, string2));
    		printf("String1: %s String2: %s\n", string1, string2);
    	}
    }
    
    char *mystrcat(char *s, char *p)
    	{
    	size_t i,j;
        for (i = 0; s[i] != '\0'; i++);
        for (j = 0; p[j] != '\0'; j++)
            s[i+j] = p[j];
        s[i+j] = '\0';
        return s;
    	}

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    In your function prototype, you say you will be passing a char and a char. But, you really want to pass a char pointer and a char pointer.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    58
    Try this:

    Code:
    char mystrcat(char *, char *);

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    12
    thank you!
    looking at it now, i can see it plain and simple.
    i guess it was the age old, you read your work, but see what you think is there

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Btw, parameter 2 should really be const.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Question about function prototypes
    By Mikecore in forum C Programming
    Replies: 2
    Last Post: 11-20-2005, 05:39 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM