| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi, this is a snippet of a little something i'm trying out, I'm pretty new to C++ so please be patient with me
//-start of code if (strcmp("checkvalues", gx[1]) == 0 ) { for (int i=4; gx[i] == NULL; i++) send_socket(irc, "PRIVMSG kenneal :values are %s\r\n",gx[i]); } //-end of code values of gx[i] will return stuff like @glglgl, @abcde, @kckckc, !@acb, ^@kkb. Let's say I want to take only the words after @. What can I do with my current code to do it? Any help will be greatly appreciated. |
|
#2
|
|||
|
|||
|
First off, get rid of the NULL characters at the begining of your string (gx[]). C/C++ uses the NULL character to mark the end of string. Second off make sure gx[] is terminated with a NULL char. Third off you can use the index() function to locate the "@" in your string. Set a char* to one after this and away you go.
Assuming you get rid of the NULL characters at the begining of gx[] char *cptr = index(gx, '@'); ++cptr; cptr now points to your string. |
|
#3
|
|||
|
|||
|
char *cptr = index(a[i], '@');
returns these errors.. on this very same line. it seems index isnt recognised as a function and is directly interpreted as something else error C2065: 'index' : undeclared identifier error C2440: 'initializing' : cannot convert from 'int' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast I'm new to programming and the compiler I use is Microsoft Visual C++ 6.0 so im wondering if that may have caused some problems... Edit: oh i searched a bit more on google, and i tried and it works. char *fullstringiwant = strpbrk(gx[i], "@" ); Thanks for your help BoolBoob. But i'm still unsure of what is happening above, it will be so nice if you can still explain to me about the errors i encountered. Thanks a lot |
|
#4
|
|||
|
|||
|
You need to include <strings.h> to access index, but you've obviously already done that as strcmp() works. Perhaps Microsoft has deprecated index() in favor of strpbrk(). I don't develop using MS stuff so I really don't know.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > A small C++ problem.. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|