ifstream inputfile;
	cout << "enter the name of the file: ";
	cin >> filename;
	inputfile.open(filename);
	string temp;
	int i = 0;

	while(filename != NULL)
	{
		while(isalpha(filename))
		{
			temp[i++] = filename;
		}
		if(i > 0)
		{
			insert(temp, 1);
			i = 0;
		}
	}

this is my code, what am I doing wrong?

I'm creating a linked list(not a part of the question asked), I'm inserting all the words from a file into the list.

am I extracting the word the wrong way? someone please show me the light :)

nvm, figured it out :)

You're OK till the while loop - what's it supposed to be doing?

How about something like:

if( inputfile ) //file opened, let's do some work
{
   while ( inputfile >> temp ) //gets one word at a time
   {                            //if successful, store the word
           list.insert( temp );
           i++;    //just so you know how many you've inserted
    }
}

Once you've opened the file named in filename, you don't need to use that variable for anything.

isapha( ) takes single characters as its argument, not a string.

nvm, figured it out :)

Care to share? Sure you got it right?

Care to share? Sure you got it right?

sure :)

void file(char filename[])
{
	List l;
	ifstream inputfile;
	cout << "enter the name of the file: ";
	cin >> filename;
	inputfile.open(filename);
	char temp[SIZE];
	string temp2;
	
	while(inputfile != NULL)
	{
		inputfile >> temp;
		int i = 0;
		while(temp != NULL)
		{
			temp[i] = tolower(temp[i]);
			i++;
		}
		temp2 = temp;
		l.insert(temp2, 1);
	}
	
}

Sure this is working right?

how about while( temp[i] != NULL ) temp itself will never be NULL in this usage.

commented: showed me the light on writing datas to array +1

Sure this is working right?

how about while( temp[i] != NULL ) temp itself will never be NULL in this usage.

thank you!! I was wondering why my program kept crashing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.