Buffer problem

I have to read in lines of text and append them to a char buffer[1000]. replace all the newline '\n' characters with '\0' terminators. i also have to have an array char* lines[100] so that the pointers in that array point to the beginnings of lines in the text. then display the lines in reverse order starting with the last input line. I've gotten most of it done but I'm stuck at this particular error I'm getting. Hopefully someone can help tell me what I'm doing wrong and what I need to correct it? Thanks a ton! Please see below:


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
 #include <iostream>
#include <fstream>
#include <cstring>
#include <string>

using namespace std;

int main()
{
   char buffer[1000];
   char* lines[100];
 
   int bsize = 0;
   int lsize = 0;

   bool more = true;
   bool newline = true;
   string temp="";
   string file_text="";
   while (more)
   {
   ifstream in_stream("in.txt");
   while(!in_stream.eof())
   {
	   getline(in_stream,temp);
	   file_text=file_text+(temp+='\0');
	   char* foo=new char[file_text.size()+1];
	   strcpy (foo, file_text.c_str());
	   char* p=strtok (foo," ");

   }
 

     if (bsize >= 1000) 
	 {
		 more = false;
	 }
      if (newline)
      {
         if (lsize < 100)
         {
            lines[lsize] = buffer + bsize;
            lsize++;
            newline = false;
         }
         else more = false;
      }
      if (more)
      {
         if (p == '\n')
         {
            buffer[bsize] = '\0';
            bsize++;
            newline = true;
         }
         else
         {
            buffer[bsize] =p;
            bsize++;
         }
      }
   }
   buffer[1000 - 1] = '\0';

   for (int i = lsize - 1; i >= 0; i--)
   {
      cout << lines[i] << "\n";
   }

   system("pause");
   return 0;
}
 




in.txt

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
94
95
96
97
98
99
100
 adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds
adsf
adsf
asd
ds
ds


Couldn't you just read everything into a single string with a bunch of getlines, then use .find() to replace all the '\n's with '\0's and print it or copy it?
Topic archived. No new replies allowed.