• Welcome to Valhalla Legends Archive.
 

[C++] Visual Studio Exploded

Started by R.a.B.B.i.T, November 06, 2004, 04:06 PM

Previous topic - Next topic

R.a.B.B.i.T

I can't figure out what went wrong, because this works at school and at my friend's house.  Reinstalling didn't work.  Getting SP's didn't work.  I'm out of ideas...

Quote--------------------Configuration: rawr - Win32 Debug--------------------
Compiling...
rawr.cpp
e:\program files\microsoft visual studio\vc98\include\lvp\string.cpp(59) : error C2065: 'strlen' : undeclared identifier
e:\program files\microsoft visual studio\vc98\include\lvp\string.cpp(62) : error C2065: 'strcpy' : undeclared identifier
e:\program files\microsoft visual studio\vc98\include\lvp\string.cpp(346) : error C2065: 'strncmp' : undeclared identifier
e:\program files\microsoft visual studio\vc98\include\lvp\string.cpp(374) : error C2065: 'strcmp' : undeclared identifier
Error executing cl.exe.

rawr.exe - 4 error(s), 0 warning(s)
Offending lines:
String::String(const char * s)
{
assert (s != 0);

myLength = strlen(s); // offending line 59
    myCapacity = myLength + 1;
    myCstring = new char[myCapacity];
    strcpy(myCstring,s); //offending line 62
}

int String::find(const String & str)  const
{
    int len = str.length();
    int lastIndex = length() - len;
    int k;
    for(k=0; k <= lastIndex; k++)
    {
        if (strncmp(myCstring + k,str.c_str(),len) == 0) return k; // offending line 346
    }
    return npos;
}

bool operator == ( const String & lhs, const String & rhs )
{
    return strcmp(lhs.c_str(), rhs.c_str()) == 0; // offending line 374
}


The library I am using is here: http://www.lvp.com/data/cpluspc/

UserLoser.


Newby

Or why not just use a regular character array?
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

R.a.B.B.i.T

string.h dislikes me more than the LVP library.

Character arrays cannot be passed as reference.

[edit]
Updated the strcmp libraries and whatnot (after a couple hours on google), it works now.

Newby

#4
Quote from: R.a.B.B.i.T on November 06, 2004, 09:06 PM
Character arrays cannot be passed as reference.
As far as I can remember, if you pass the address of the first character in the array, it'll technically be passed as reference.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void SomeSub(char *Buffer)
{
strcpy(Buffer, "Rabbit sux");
return;
}

int main()
{
char Buffer[48];
SomeSub(Buffer);
printf("%s\n", Buffer);
system("pause");
return 0;
}

Output: Rabbit sux

Took me ~2 minutes to write.

So eh?
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

R.a.B.B.i.T

But that requires you to predefine a string length.

Newby

Quote from: R.a.B.B.i.T on November 07, 2004, 09:51 AM
But that requires you to predefine a string length.
Oh noes?

Why not just allocate space as needed like this?

char *Buffer = new char[1048]

Again, I'm not sure if that's exactly it, but it's something along those lines.

And this has been discussed before, on how to resize character arrays.
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Mephisto

Be careful in your terminology Newby & Rabbit.  A passing a reference and passing by reference are two different things.  Passing by reference can be accomplished by either passing the address or a pointer pointing to the data or passing a reference variable to the data.  A reference is that variable.  Passing by reference is passing that reference or address into the function which can be accomplished with references or pointers.  Also note that character arrays (and arrays in general) are passed by reference by default (their addresses are passed into the function, not copied).