Hello, everyone.

Today, I'm working on giving myself a headache.

The reason is simple. I'm rusty on, or maybe ignorant of, dynamic declaration of arrays.

What I'm doing is MFC related, but I've got the MFC questions ironed out for the most part. Now, I've got to make a good storage system for CStrings.
I want to use an array of pointers to CStrings. The problem is, I don't know how many pointers I'll need until after I've opened a text file.
But wait, it's not that simple. I've written an int-returning '\n' counter, and it goes-a-like this:

int textlinecount(FILE* fp)
{
	int counted = 0;
	
	while(!feof(fp))
	{
		if(getc(fp)=='\n'||feof(fp))
			counted++;
	} 
	rewind(fp);//Return to start of file for use by textreadandupdate.
	return counted;
}

<< moderator edit: added [code][/code] tags -- learn to do so yourself >>

That should work just fine. What is wrong, though, is that this, and the CString pointer array, are part of the same class declared at startup, before a file is loaded.
Then, I use this to read in the file information.

BOOL TextReadAndUpdate(FILE* filetoread)
{
	char str[50];	
	while(!feof(filetoread))
	{
		for(int i=0;i<50;i++)
		{
			str[i]=getc(filetoread);

			if(str[i]=='\n'||feof(filetoread))
			{
				if(feof(filetoread)&&(i<50))
				{
					while(i<50)
					{						
						str[i] = ' ';
						i++;
					}
				}
				txtContents = (CString)str;
					UpdateAllViews(NULL);
				break;
			}

		}			

	}

	return TRUE;
}

<< moderator edit: added [code][/code] tags >>

Given the nature of MFC and not wanting to make the information array exist outside this 'document' class, how do I dynamically allocate a number of pointers after the class is... er... loaded..declared..initialized... by the program?

I think I should include 'CString *lineptrs;' in the header file, but I'm not sure how to continue after that.

Thank you for your time.

The solution that comes to mind is a doubly-linked list.

That means trouble.
Lessee... head, tail, frame transverse head, frame transverse tail... yipeeskipee. There go my hopes of easy pointer arithmetic to control the view...

Upon yet further reflection:
This is the best way to implement the program, as it allows me to add more functionality that is going to be required in future updates with very little fuss.

No more whining.

Status of Puzzle:
Resolved.

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.