-
September 21st, 2013, 06:36 PM
#1
parsing a line for words...
Hi,
I'm getting this when I compile my program. Then, when the program runs I get an error. I assume it is because I have the warning for this problem. How can get around this error.
warning C4172: returning address of local variable or temporary
Code:
#include <iostream>
#include <cstring>
using namespace std;
char* parse_words(char* pstr, int strp);
int main()
{
char* strin("This is the string to be parsed");
cout << " String is: " << strin << " Length is: " << strlen(strin) << "\n\nParsing...\n";
/* cout << "Please enter a string to parse word-by-word: \n";
cin >> strin;
cout << "This is the string entered: " << strin << " \n.";
*/
//char * p(nullptr);
char* p = parse_words(strin, strlen(strin));
//char* p = parse(s1);
while (p)
{
std::cout << p << "\n.";
delete [] p;
p = parse_words(nullptr, strlen(strin));
}
return 0;
}
char* parse_words(char* pstr, int strp)
{
static int start(0);
static int len(strp);
cout << "Value of len: " << len << '\n';
int lenpm(len);
int pos(0);
int x;
char* pReturn(nullptr);
int holdlen(20);
char holdarea[20];
cout << "Start start loop\n";
for (start; start <= len; start++)
{
cout << "Start loop: \n";
for (x = 0; x <= holdlen; x++)
{
holdarea[x] = ' ';
}
if (*pstr != ' ')
while (*pstr != ' ')
{
holdarea[x] = *pstr;
x++;
*pstr++;
start++;
}
return holdarea;
}
return pReturn;
}
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
|
Click Here to Expand Forum to Full Width
|