#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
using namespace std;
int cal_row() // calculate the row of textfile
{
ifstream textfile;
textfile.open("textfile.txt");
textfile >> noskipws;
int row = 1;
char char1;
while (textfile >> char1)
{
if (char1 == '\n')
{
++row;
}
}
return row;
}
char data()
{
ifstream textfile;
textfile.open("textfile.txt");
textfile >> noskipws;
char line, char2;
int row, len = 1000, tlen;
row = cal_row();
tlen = row * len + 1;
char data1[tlen];
char *data2[tlen];
len = 0;
while (textfile >> char2) // store text as an array
{
if (char2 != '\n')
{
data1[len++] = char2;
}
else
{
data1[len++] = '\n';
}
}
for (int i = 0; i <= tlen; i++) // uppercase to lowercase
{
if ((int)data1[i] <= 90 && (int)data1[i] >= 65)
{
data1[i] += 32;
}
}
return *data1;
}
int main()
{
int row = cal_row(), tlen = row * 1000 + 1, len1, len2, len3;
len1 = len2 = len3 = 0;
char text1[tlen], text2[row][20][51];
*text1 = data();
return 0;
我想知道如何修改代码,使得主函数中text1的数组可以和data函数中的返回值相同(即text1=分函数中的data1)