debug error

I am writing a code to read a file and break it into lines and characters but I am getting an error do not know the reason for it though.

here is my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<fstream>
#include<string>
#include<iostream>
#include<cstring>
#include<conio.h>
#include<cstdlib>
#include<stdlib.h>

using namespace std;

 bool isop(char c)
{
	if(c=='+'||c=='-'||c=='*'||c=='/')
	{
		return true;
	}
	return false;
}

bool isdel(char c)
{
	if(c==';')
	{
		return true;
	}
		return false;
}
int CALCULATE(int current_state,char letter)
{
	int new_state;
	return new_state;
}

/* string LEXER(string word)
{
	int state=0;
	for(int i=0;i<=word.length()-1;i++)
	{
	state= CALCULATE(state,word[i]);	
	}
}*/
 void SPLIT(string line)
{
	
	char *a=new char(line.length());
	strcpy(a,line.c_str());
	//a[line.length()]='\0';
	
	string word="";		
	
	for(int i=0;i<=line.length()-1;i++)
	{
		if(a[i] != ' ' && !isdel(a[i]) && !isop(a[i]))
		{
		
			//cout<<LEXER(word);
			word=word+a[i];
		
		}
		else
		{
			cout<<word<<endl;
			if(isdel(a[i]))
			cout<<"Delimeter\t"<<a[i]<<endl;
			else if(isop(a[i]))
			cout<<"Operator \t"<<a[i]<<endl;
			word="";
		
		}
		
	}
}

int main(int argv, char **argc)
{
	string line;
	//ifstream myfile("input.txt");
	ifstream myfile;
	myfile.open("C:/Users/User Name/Documents/ppl 2014/input.txt");
	cout<<"Hello";
	while(getline(myfile,line))
	{
		cout<< line<<endl;
		SPLIT(line);
	}
	
	myfile.close();
	
	getch();
    return 0;
}


here is the input file
[input]
hello;world cse340 asu 2013/05/31 // end
boolean $xx= ((((((((23WE + 44 - 3 / 2 % 45 <=17) > 34.45;
"hello23.1 '-)">-''' //this is an error!
(1 + 09 // "it is ok"
'\a' = 'a'
[/input]

The first line is executing properly but when it goes to the second line I get an error "the program has stopped working"
Please look into it
Thanks in advance
http://www.cplusplus.com/forum/general/112111/

1
2
	char *a=new char(line.length());
	strcpy(a,line.c_str());
you are reserving memory for just one character, so `strcpy()' will write out of bounds.
It should be char *a = new char[ line.length() ];, ¿but what is the purpose of that copy? ¿and why do you prefer to leak memory instead of using `std::string' ?
Topic archived. No new replies allowed.