| | |
Debugging string function
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 11
Reputation:
Solved Threads: 0
Hi,
If any of you know JavaScript, you will know about the split() member function of a string. In it's simplest form, it splits the string that you call it from by the char argument and returns an array. I found this very useful, so I tried to write it in C++. Here is the code:
Why does my compiler (Turbo c++ v 3) return errors?
If any of you know JavaScript, you will know about the split() member function of a string. In it's simplest form, it splits the string that you call it from by the char argument and returns an array. I found this very useful, so I tried to write it in C++. Here is the code:
C++ Syntax (Toggle Plain Text)
char **split(char *split_string,char splitby) { int i,j,l,sslen=strlen(split_string); /* 'k' is a global variable that I can access to tell me how long was the array returned when the string was processed. An example of this functions use might be char **splitup=split(mystring,' '); */ char str_arr[sslen/2][sslen]; for(i=0; i<sslen; i++) { if(split_string[i]==splitby) { k++; for(j=i-1,l=0; j>0; j--,l++) { if(split_string[j]==splitby) break; str_arr[k][l]=split_string[j]; } } } if(k=0) strcpy(str_arr[0],split_string); return str_arr; }
Why does my compiler (Turbo c++ v 3) return errors?
•
•
•
•
Why does my compiler (Turbo c++ v 3) return errors?
char str_arr[sslen/2][sslen];
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Dec 2004
Posts: 11
Reputation:
Solved Threads: 0
I removed the non-constant array dimensions. Now it "Cannot convert 'char[300] *' to 'char * *' in function split(char *,char)".
My previous error messages:
Ignore the line numbers, xstring.h has a little more in it.
My previous error messages:
C++ Syntax (Toggle Plain Text)
Error C:\SINBAD\CPP\LIBRARY\xstring.h 55: Constant expression required in function split(char *,char) Error C:\SINBAD\CPP\LIBRARY\xstring.h 55: Constant expression required in function split(char *,char) Error C:\SINBAD\CPP\LIBRARY\xstring.h 72: Cannot convert 'char[1] *' to 'char * *' in function split(char *,char) Error testing.cpp 24: Lvalue required in function main(int,char * *)
Ignore the line numbers, xstring.h has a little more in it.
•
•
•
•
Originally Posted by sinB
Now it "Cannot convert 'char[300] *' to 'char * *' in function split(char *,char)".
If I had a better idea of what the expected input and output of the function were, I could give better help. *Sorry*
Are you familiar with the STL?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- How do I pass String into a function in C++? (C++)
- Problem with string to function argument (C++)
- how to pass string into function (C++)
- question about php string function (PHP)
Other Threads in the C++ Forum
- Previous Thread: Best free C/C++ compiler for a newbie?
- Next Thread: getline() error when cin is redirected
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






