trying to load a .txt file into a string

# include <stdio.h>
# include <stdlib.h>
# include <iostream>



#define ELEMENT 300
#define LENGTH 20
void loadfile(char str[ELEMENT][LENGTH])

{
FILE *filepointer;
int wordnum, is_end, poswithin;
char read_char;
filepointer=fopen("demo1.txt","r");
poswithin=0; wordnum=0;
is_end=fscanf(filepointer,"%c",&read_char);

while (is_end!=EOF)

{
if (isupper(read_char) || islower(read_char))
{

str[wordnum][poswithin]=read_char; poswithin++;
}

else
{
str[wordnum][poswithin]=(char)'\n';
poswithin=0; wordnum++;
}

is_end=fscanf(filepointer,"%c",&read_char);
}

fclose(filepointer);
}

it says it has a problem with an unresolved externals
Hey I'm not too sure about this but it's one of two things:

1. You forgot to put using namespace std;
or
2. If you have multiple files you may have linked them up incorrectly try have one main.h where all the header files are included and all of your .cpp files have #include "main.h" at the top

Hope this helps :)

Oh and by the way can I ask why you are using File *myfile and not ifstream *myfile, just curious.
I was very kind and created a solution that DOES work without errors, but it's with ifstream, so if you don't won't to use it for some reason try my second suggestion in my first post

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



std::string loadfile(std::string fileName)
{
	std::string line;;
	std::ifstream myFile;
	myFile.open(fileName);
	if(!myFile.good())
	{
		std::cout << "Error opening file";
		return "ERROR";
	}

	while(!myFile.eof())
	{
		getline(myFile, line);
	}
	myFile.close();

	return line;
}

int main(int argc, _TCHAR* argv[])
{
	
	std::cout << loadfile("Text.txt");
	return 0;
}

Topic archived. No new replies allowed.