atoi on FILE

I am doing a cashier type of program, where in I have to convert the last part of the file since it's the stock. It's not yet complete but I'm stuck after doing the "How many?" the program stops right there.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
 
void BuyInv()
{
		cout<<endl<<endl;
		FILE *fileVar2 = fopen ("Order.txt", "a");
		FILE *fileVar = fopen ("Inventory.txt", "r");
		int temp = 0;
		int many;
		char item[1000];
		char data[2000];
		flushall();
		cout<<"What would you like to buy?"<<endl;
		gets (item);
		int i = 0;
		int wordLength = strlen (item);
		while (i < wordLength)
		{
			if (isspace (item[i]))
			{
				item[i] = '_';
			}
			i++;
		}
		flushall();
		char* order = new char;
		while (!feof(fileVar))
		{
			fscanf (fileVar, "%s\n", &data);
			char* wordSplit = strtok (data, ",");
			if (wordSplit != NULL)
			{
						if (strcmpi (item, wordSplit) != 0)
						{
							temp = 1;
							continue;
						}
						else if (strcmpi (item, wordSplit) == 0)
						{
							temp = 0;
							while (wordSplit != NULL)
							{
								strcpy(order, wordSplit);
								fprintf (fileVar2, "%s", order);
								wordSplit = strtok (NULL, ",");
								fprintf (fileVar2, ",", order);
								
							}
						
						fprintf (fileVar2, "\n", order);
						break;
						}
						wordSplit = strtok (NULL, ",");
			}			
		}
		fclose (fileVar);
		fclose (fileVar2);
		if (temp == 0)
		{
			flushall();
			cout<<"How many?"<<endl;
			cin>>many;
			fileVar = fopen("Order.txt", "r");
			char data2[1000];
			int temp2 = 0;
			while (!feof(fileVar));
			{
				fscanf (fileVar, "%s\n", &data2);
				char *wordSplit =strtok (data2, ",");
				while (wordSplit != NULL)
				{
					cout<<wordSplit<<endl;
					wordSplit  = strtok (NULL, ",");
					cout<<wordSplit<<endl;
					wordSplit  = strtok (NULL, ",");
					cout<<wordSplit<<endl;
					wordSplit = strtok (NULL, ",");
					/*int num = atoi(wordSplit);	
					if (many > num)
					{
						temp2 = 1;
						break;
					}
					else
					{
						temp2 = 0;
						break;
					}*/
				}
			}
			fclose(fileVar);
			if (temp2 == 1)
			{
				cout<<"Not enough Stock"<<endl;
			}
			else if (temp2 == 0)
			{
				char x;
				cout<<"Press Enter to Purchase."<<endl;
				cout<<"Press Escape to void."<<endl;
				do
				{
					x = getch();
				}while (x != 13 || x != 8);
			}
		
		flushall();
		cout<<endl<<endl;
	}
		else if (temp == 1)
		{
			cout<<"Item not found!"<<endl;
			system ("PAUSE");
		}
}

void Order()
{
	system("cls");
	FILE* fileVar = fopen ("Menu.txt", "r");
	char data[2000];
	char c;
	while (!feof(fileVar))
	{
		fgets(data, 999, fileVar);
		cout<<data;	
	}
	cout<<endl<<endl;
	BuyInv();
	
	
}


void main()
{	
		FILE *fileVar2 = fopen ("Order.txt", "w");
		int c;
		do
		{
		system("cls");
		cout<<endl<<endl<<endl<<endl;
		cout<<"\t\t\t\t\t ";
		Sleep(50);cout<<"W";Sleep(50);cout<<"E";Sleep(50);cout<<"L";Sleep(50);cout<<"C";
		Sleep(50);cout<<"O";Sleep(50);cout<<"M";Sleep(50);cout<<"E\n";
		cout<<"\t\t\t\t\t";
		Sleep(50);cout<<"   ";cout<<"t";Sleep(50);cout<<"o\n";
		cout<<"\t\t\t\t\t";
		Sleep(50);cout<<"P";Sleep(50);cout<<"C";Sleep(50);cout<<"T";Sleep(50);cout<<"A";Sleep(50);cout<<"M";Sleep(50);cout<<"B";
		Sleep(50);cout<<"A";Sleep(50);cout<<"Y\n";
		cout<<endl;
		Sleep(150);
		cout<<"\t\t\t\t";
		cout<<"1)Order"<<endl;
		Sleep(150);
		cout<<"\t\t\t\t";
		cout<<"2)Exit"<<endl;
		Sleep(150);
		cout<<"\t\t\t\t";
		cout<<"Choose: ";
		cin>>c;
		
		if (c == 1)
		{
		Order();
		}


		}while (c != 2);

}
Topic archived. No new replies allowed.