|
-
Goldfish
String in C++
I am trying to use a function to save a word to a global string, depending on what the user input was.
the code goes like this:
Code:
char g_string[255]; //declare global sting
int main(void)
{
//main program
}
int changestring(int y)
{
switch (y)
{
case 1:
{
strcpy (g_string, "word to be used");
break;
}
case 2:
{
strcpy (g_string, "other word");
break;
}
}
return 0;
}
When I compile, I get the message 'strcpy' is 'unidentified'
what am I doing wrong?
please help.
thanx.
Possesions never meant anything to me,
I'm not crazy.
Well that's not true I have a bed,
and a guitar and a dog named dog.
-
NullPointerException
I think you need to #include <string.h>
Open Source is free like a puppy is free.
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.
Understanding Evolution
-
Stormtrooper Mod
Yep, you need either
#include <string.h>
or
#include <string>
using namespace std;
Also, you can try using the actual C++ string type as well instead of using an array. Just declare some variable string variablename.
Proofread carefully to see if you any words out.
[the rules]
-
Goldfish
Thanx guys, I'll try that
Possesions never meant anything to me,
I'm not crazy.
Well that's not true I have a bed,
and a guitar and a dog named dog.
-
Mako Shark
Originally posted by Pinky
Yep, you need either
#include <string.h>
or
#include <string>
using namespace std;
Also, you can try using the actual C++ string type as well instead of using an array. Just declare some variable string variablename.
just a nitpick but <string> in c++ is for the class std::string, for c string functions like the ones found in c's string.h, use <cstring>
-
Reef Shark
I think the problem lies in this little distraction -> g_string
:P sorry... too much coffee this morning... too little food.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|