Results 1 to 6 of 6

Thread: simple problem!!!?

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    simple problem!!!?

    Code:
    #include <iostream.h>
    #include <string.h>
    #include <stdio.h>
    
    char test(const char s1[10],const char s2[10]);
    
    char test(const char s1[10],const char s2[10])
    {
    strcat(s1,s2);
    cout<<s1;
    
    return 'a';
    }
    
    int main()
    {
    	test("hello", "there");
    return 0;
    }
    I get the error - 'strcat' : cannot convert parameter 1 from 'const char []' to 'char *'Conversion loses qualifiers.

    I've tried every combination. Do you know whats wrong? Thanks
    Matt

  2. #2
    Megatron
    Guest
    How about just changing the function to this:
    Code:
    char test(const char* s1,const char* s2)
    {
    	char* tmp;
    	strncpy(tmp,s1,10);
    	strncat(tmp, s2,10);
    	cout << tmp;
    
    	return 'a';
    }

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Why are you just returning 'a'. If you don't use it make the function void, cos you dont have to return anything.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  4. #4

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    i know, it was originally intended to return something, but for testing i did not need it so just put a filler.
    Matt

  5. #5

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    Megatron, I get the warning char *tmp used without being initialized. If I try and exacute anyway I get an illegal operation on startup.
    Matt

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    char test(const char* s1,const char* s2)
    {
    	cout << s1 << s2;
    	return 'a';
    }
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width