Reading from a text file

Hi everyone !
just need a bit of knowledge from your overflowing stack ! :)

i got an assignment to do...and in that i need to get the inputs from a .txt file....and im not getting how to read the data i want and skip the rest thrash.
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
Lambton:

Name: chocolate
demand rate: 50
setup cost: 200
unit cost: 5.2
inventory cost: 2
selling price: 3

weeks: 6

Name: cake
demand rate: 50
setup cost: 300
unit cost: 4
inventory cost: 2
selling price: 3.1

weeks: 12

Callaghan:

Name: coffee
demand rate: 100
setup cost: 200.5
unit cost: 4
inventory cost: 2.1
selling price: 2

weeks: 50

program is about a coffee shop with two branches and i have to keep track of the stock in the stores.
Lambton and Callaghan are the stores.
how can i read them ? im not sure
i know how to open the file to be read..
confused after that..
I don't see anywhere in the data above what the inventory is, so it looks like your might be tracking the demand rate.

The constant in your date file is Name: and weeks:


so you would write something like
getline string
if string!="Callaghan:"
getline name
getline demand
getline unitcost
getline inventorycost
getline sellprice
getlline weeks

You now have it all read for each product, Then you only use the data you want.

Another way maybe better would be to see if each line contains "Name:" then read the data lines.
@samueladams
thanks alot for reply mate.
our study system in australia is a bit self based we were just told how to open and close the files but we have been given this tough program.
and we are using microsoft visual studio 2010 c language
"printf scanf fprintf f scanf"
so the getline thing is now working in here...
it will be somthing fscanf and fprintf

here's my code till now for you to understand it more accurately

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
#include <string.h>
#include "stdafx.h"
#include<math.h>
#include<stdio.h>

typedef struct{
	char name[12];
	int demandrate;
	double setupcost;
	double unitcost;
	double inventorycost;
	double sellingprice;
	double eoq;
}product_t;

product_t coffee;
product_t choc;
product_t tea;
product_t cake;
product_t pie;

typedef struct{
	product_t coffee;
	product_t choc;
    product_t tea;
    product_t cake;
    product_t pie;
}stores_t;
stores_t callaghan;
stores_t lambton;


	


					

int main(void)
{
	int selection;
    FILE *f_in;
	char store1[8]="lambton";
	char store2[11]="callaghan";


	printf("Welcome To Bestbean Coffee Replenishment System\n");
	printf(" 1.Read File\n 2.Input Data\n 3.Display Store\n 4.Display Product\n 5.Save File\n 6.Exit\n What Would you Like To Do?(1-6)\n >");
	scanf("%i",selection);
	
	if (selection == 1);{/*Read File*/
		f_in =fopen("input.txt","r");
		if (f_in == NULL){
			printf("No File Found");
		}
		else{
			fscanf("%s
			
		}



	}


	if (selection == 2);{/*Input Data*/

	}

	if (selection == 3);{/*Display Store*/
	}

	if (selection == 4);{/*Display Product*/
	}

	if (selection == 5);{/*Save File*/
	}

	if (selection == 6);{/*Exit*/
	}

	




	return 0;
} 


The program is about a coffee shop brand which have two shops in suburbs of lambton and callaghan.
and each shop have 5 products coffee,chocolate,tea,cake,pie.
and each product have some data which the owner need to be aware of like name of product,demand rate,setup cost,unit cost,inventory cost,selling price,and another calculated value EOQ(economic Order Quantity).
on basis of this we need to make a program with the first screen asking for input from user like this.
Topic archived. No new replies allowed.