file input-output; getline; stuck.

deleted.
Last edited on
Think of using character arrays like this:
Let's say we have an array the length of a name "Evan". This array MUST be 5 spaces long to contain that name because c-strings always tack on a "null-termination character at the end: '\0' ...
In order to traverse this array I need to step through each index of that array in order to access the letter in that index.
For example.
1
2
3
4
5
6
char name[5] = {'E', 'v', 'a', 'n'}; //be sure to include the single-quotes around letters

for (int i = 0; name != '\0'; i++)
{
    cout >> name[i];
}

that snippet of code will allow me to output the 'name' character array, until i reach the null-termination.


Maybe this will help you get in the right direction
Parasin:

I am actually having the same issues as the person who started this thread, the issue wasn't with the chars itself but how to get the employees matched up with their data, mine just isn't working period the way that it is supposed to be.
why do you open sales.txt in main if your not going to use it?

what is this supposed to do because currently it does nothing.
enter.getline(dataPerWeek, 5);

in the first line of your file you have a 3 which you extract with enter >> weeks; but you need to remember that you don't just have a 3 on this line you also have a newline. So the first line looks like 3 '\n' when you use the statement enter >> weeks; you extract the 3 but the newline is still there. By default getline extracts characters until it sees a newline so when you call enter.getline(dataPerWeek, 5) getline sees a newline right away removes the newline without extracting any data.

this is an infinite loop
1
2
3
4
	while (salesCount < totalSales)
	{
		cout << Employee1[50];
	}



and Employee1[50] doesn't exist

don't forget to close your files

you would be much better off using strings
Last edited on
going to dissect this and try the string route and see how far I get. thanks everyone for the input so far.
Topic archived. No new replies allowed.