Strcmp help !

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
#include"stdafx.h"
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
void convert(char *a);

void lower(char *storeinput);


typedef struct{
	char name[20];
	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=0;
    FILE *f_in;
	char store1[]="lambton";
	char store2[]="callaghan";
	char cancel[]="cancel";
	char STOREinput[20];
	char storeinput[20];
	char productinput[20];
	char coffee[]="coffee";
	char chocolate[]="chocolate";
	char tea[]="tea";
	char cake[]="cake";
	char pie[]="pie";
    
while (true)
{

	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){
		}


	     if (selection = 2){/*Input Data*/
		     printf("INPUT DATA\n");
	     do{
	            printf("Please,input the name of the store:\n(type 'cancel' to return to the previous menu) >");
		        scanf("%s",&storeinput);
                lower (storeinput);

				if( strcmp (storeinput,store1) == 1){
		        printf("No such Store Found\n\n\n");
				}
				else if( strcmp (storeinput,store2) == 1){
					printf("No such store found\n\n\n");
				}
				
				else if( strcmp (storeinput,store1) ==0 ){/* Lambton*/ 
							printf("Please, input the name of the product: >");
							scanf ("%s",productinput);
							lower (productinput);

					      if( strcmp (productinput,coffee) ==0){
							  printf("please");
								
								}
								if( strcmp (productinput,chocolate) ==0){
									  }
									  if( strcmp (productinput,tea) ==0){
					                       }
						                   if( strcmp (productinput,cake) ==0){
						                        }
						                        if( strcmp (productinput,pie) ==0){
						                             }
				    }
				  
				
			 
		 
				else if( strcmp (storeinput,store2) ==0 ){
					         printf("callaghan\n\n");
		          } 
		   
				
		   }
	     while(strcmp(cancel,storeinput)!=0 || strcmp(cancel,productinput) !=0);
		 }
	if (selection == 3){/*Display Store*/
	}

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

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

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

return(0);
}
void lower(char *storeinput){
	int i,z;
	z = strlen(storeinput);
	for(i=0;i<=z;i++){
			storeinput[i]=tolower(storeinput[i]);
	}
}


hi guys im trying to come over this problem but i think i lack some knowledge and i am stuck to this code.
all i want is that the user enters the number from 1-6 whatever he wants to do..but for now just option 2 input data...
after selecting 2 he will get to a loop because i want that whenever he types cancel it goes up to the main menu..
now it should work like the user selects 1-6 and assuming he selects 2 and now he enters store name in this case they are only 2(lambton and callaghan).

if the user enters a third name the program shows no such store found ...
but this code is crazy...i enter lambton and it says no such store found..
can someone rectify the prob.?
anyone ?
Line 71 - you have selection = 2, needs to be selection == 2.

You don't really need the lower function - just use stricmp or strcasecmp depending on your compiler - it is the case insensitive comparison.

You have weird logic in lines 78-85. It should be removed. Your code should look more like:

1
2
3
4
5
6
7
if ( strcmp (storeinput,store1) ==0 ) {
  // ... lambton
} else if ( strcmp (storeinput,store2) ==0 ) {
  // ... callaghan
} else {
  // No store found
}


Good luck!

EDIT: Oh by the way, this strcmp(cancel,storeinput)!=0 || strcmp(cancel,productinput) !=0 should be changed to strcmp(cancel,storeinput)!=0 && strcmp(cancel,productinput) !=0 in line 113
Last edited on
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
172
173
174
175
176
177
178
179
180
181
182
183
#include"stdafx.h"
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
void convert(char *a);

void lower(char *storeinput);


typedef struct{
	char name[20];
	int demandrate;
	double setupcost;
	double unitcost;
	double inventorycost;
	double sellingprice;
	double weeks;
	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=0;
    FILE *f_in;
	char store1[15]="lambton";
	char store2[15]="callaghan";
	char cancel[10]="cancel";
	char STOREinput[15];
	char storeinput[15];
	char productinput[15];
	char coffee[10]="coffee";
	char chocolate[10]="chocolate";
	char tea[10]="tea";
	char cake[10]="cake";
	char pie[10]="pie";
    
while (true){


	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)
		  {
		  }
         
		  
		  if (selection == 2)/*Input data*/
		  { 
			  printf("INPUT DATA\n");

			  do{
				  printf("Please,input the name of the store:\n(type 'cancel' to return to the previous menu) >");
		          scanf("%s",&storeinput);
                  lower (storeinput);

				  
		          if(strcmp (storeinput,store1) ==0 ){/*Lambton*/
					        printf("Please, input the name of the product: >");
							scanf ("%s",productinput);
							lower (productinput);

							if (strcmp (productinput,cancel) ==0){
								break;

							}else if( strcmp (productinput,coffee) ==0){
								printf("Please, input the demand rate of coffee: >");
								scanf("%d",&lambton.coffee.demandrate);
								printf("Please, input the setup cost of coffee: >");
								scanf("%d",&lambton.coffee.setupcost);
								printf("Please, input the unit cost of coffee: >");
								scanf("%d",&lambton.coffee.unitcost);
								printf("Please, input the inventory cost of coffee: >");
								scanf("%d",&lambton.coffee.inventorycost);
								printf("Please, input the selling price of coffee: >");
								scanf("%d",&lambton.coffee.sellingprice);
								printf("Please, input the number of weeks: >");
								scanf("%i",&lambton.coffee.weeks);

								return(0);
						    
							       }else if(strcmp (productinput,chocolate) ==0){

							              }else if(strcmp (productinput,tea) ==0){

							                      }else if(strcmp (productinput,cake) ==0){

								                        }else if(strcmp (productinput,pie) ==0){

										             }



				  }else if( strcmp (storeinput,store2) ==0){
				         
				  
				        }else if( strcmp (storeinput,cancel) ==0){
								break;
				              
				              }else{
								  printf("No such store Found");
						       }
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  }while(strcmp(cancel,storeinput)==0 || strcmp(cancel,productinput)==0);
	      }
	      
		  
		  if (selection == 3)
		  {
	      }

	      
		  if (selection == 4)
		  {
	      }

	      
		  if (selection == 5)
		  {
	      }

	      
		  if (selection == 6)
		  {
	      }
	
     }



return(0);
}



void lower(char *storeinput){
	int i,z;
	z = strlen(storeinput);
	for(i=0;i<=z;i++){
			storeinput[i]=tolower(storeinput[i]);
	}
}


Thanks alot buddy ! that was a silly mistake.
i have to use lower function beacause it is in the assignment requirments !
from line 92-103

as u can see buddy i have to ask for the products info each time (i have 5 products and each product has 6 data's to store...

i am willing to make a function so i can call it everytime i need to take the inputs...
im finding it difficult because each product will have different name of memory i want to store it to.. like lambton.coffee.sellingprice , lambton.tea.unitcost , callaghan.pie.weeks etc.

can you give me an idea how u think i can deal with it ? :)
thanks again.
Anyone????
Well, while all this is still far from "nice" code, you could make a function like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void ReadProduct(const char* productName, product_t& product)
{
  printf("Please, input the demand rate of %s: >", productName);
  scanf("%d",&product.demandrate);
  printf("Please, input the setup cost of %s: >", productName);
  scanf("%d",&product.setupcost);
  printf("Please, input the unit cost of %s: >", productName);
  scanf("%d",&product.unitcost);
  printf("Please, input the inventory cost of %s: >", productName);
  scanf("%d",&product.inventorycost);
  printf("Please, input the selling price of %s: >", productName);
  scanf("%d",&product.sellingprice);
  printf("Please, input the number of %s: >", productName);
  scanf("%i",&product.weeks);
}


and then call it like this:
1
2
3
4
5
6
if( strcmp (productinput,coffee) ==0) {
  ReadProduct(coffee, lambton.coffee);
} else if ( strcmp (productinput,chocolate) ==0) {
   ReadProduct(coffee, lambton.choc);
}
...
BTW, I assume return in line 105 is there just for testing. Aaand the condition in line 145 is still wrong. It doesn't really matter because of the break statements. You should change it to either the one I showed in previous post or to while(true).
Thanks Bro !
in line 105 i used return(0) because once the operations in that loop is finished it goes up to the main menu.. i didnt wanted that.
yeh i changed in to while(true) bro !

i knew something like this will be done but didnt find examples on the forum!
bro im unclear of what this function header doing
i know we giving two values one is productname(coffee,choc,tea) and other is lambton.productname
can u please elaborate about the header ?
thanks big time !
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include"stdafx.h"
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
void convert(char *a);

void lower(char *storeinput);
void ReadProduct(const char* productName,product_t &product);


typedef struct{
	char name[20];
	int demandrate;
	double setupcost;
	double unitcost;
	double inventorycost;
	double sellingprice;
	double weeks;
	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 chocolate;
    product_t tea;
    product_t cake;
    product_t pie;
}stores_t;
stores_t callaghan;
stores_t lambton;


	


					

int main(void)
{
	int selection=0;
    FILE *f_in;
	char store1[15]="lambton";
	char store2[15]="callaghan";
	char cancel[10]="cancel";
	char STOREinput[15];
	char storeinput[15];
	char productinput[15];
	char coffee[10]="coffee";
	char chocolate[10]="chocolate";
	char tea[10]="tea";
	char cake[10]="cake";
	char pie[10]="pie";
    
while (true){


	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)
		  {
		  }
         
		  
		  if (selection == 2)/*Input data*/
		  { 
			  printf("INPUT DATA\n");

			  do{
				  printf("Please,input the name of the store:\n(type 'cancel' to return to the previous menu) >");
		          scanf("%s",&storeinput);
                  lower (storeinput);

				  
		          if(strcmp (storeinput,store1) ==0 ){/*Lambton*/
					        printf("Please, input the name of the product: >");
							scanf ("%s",productinput);
							lower (productinput);

							if (strcmp (productinput,cancel) ==0){
								break;

							}else if( strcmp (productinput,coffee) ==0){
								 ReadProduct(coffee,lambton.coffee);
						    
							       }else if(strcmp (productinput,chocolate) ==0){
 									   ReadProduct(chocolate, lambton.chocolate);
							              
							              }else if(strcmp (productinput,tea) ==0){
											  ReadProduct(tea, lambton.tea);

							                      }else if(strcmp (productinput,cake) ==0){
													  ReadProduct(cake, lambton.cake);

								                        }else if(strcmp (productinput,pie) ==0){
															ReadProduct(pie, lambton.pie);

										             }



				  }else if( strcmp (storeinput,store2) ==0){ /*Callaghan*/
					  printf("Please, input the name of the product: >");
							scanf ("%s",productinput);
							lower (productinput);

							if (strcmp (productinput,cancel) ==0){
								break;

							}else if( strcmp (productinput,coffee) ==0){
								 ReadProduct(coffee, callaghan.coffee);
						    
							       }else if(strcmp (productinput,chocolate) ==0){
									   ReadProduct(chocolate, callaghan.chocolate);
							              
							              }else if(strcmp (productinput,tea) ==0){
											  ReadProduct(tea, callaghan.tea);

							                      }else if(strcmp (productinput,cake) ==0){
													  ReadProduct(cake, callaghan.cake);

								                        }else if(strcmp (productinput,pie) ==0){
															ReadProduct(pie, callaghan.pie);
												  }
				  
				        }else if( strcmp (storeinput,cancel) ==0){
								break;
				              
				              }else{
								  printf("No such store Found");
						       }
			   }while(true);
	      }
	      
		  
		  if (selection == 3)
		  {
	      }

	      
		  if (selection == 4)
		  {
	      }

	      
		  if (selection == 5)
		  {
	      }

	      
		  if (selection == 6)
		  {
	      }
	
	 }
	 



return(0);
}



void lower(char *storeinput){
	int i,z;
	z = strlen(storeinput);
	for(i=0;i<=z;i++){
			storeinput[i]=tolower(storeinput[i]);
	}
}

void ReadProduct(const char* productName, product_t& product){
printf("Please, input the demand rate of %s: >");
  scanf("%d",&product.demandrate);
  printf("Please, input the setup cost of %s: >");
  scanf("%d",&product.setupcost);
  printf("Please, input the unit cost of %s: >");
  scanf("%d",&product.unitcost);
  printf("Please, input the inventory cost of %s: >");
  scanf("%d",&product.inventorycost);
  printf("Please, input the selling price of %s: >");
  scanf("%d",&product.sellingprice);
  printf("Please, input the number of %s: >");
  scanf("%i",&product.weeks);
}



its giving me 2 types of errors :
1) syntax error: identifier "product_t"
2) 'RealProduct':function does not take 2 arguements
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**/
#include"stdafx.h"
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
void convert(char *a);

void lower(char *storeinput);

typedef struct{
	char name[20];
	double demandrate;
	double setupcost;
	double unitcost;
	double inventorycost;
	double sellingprice;
	double weeks;
	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 chocolate;
    product_t tea;
    product_t cake;
    product_t pie;
}stores_t;
stores_t callaghan;
stores_t lambton;


void ReadProduct(product_t &product);	


					

int main(void)
{
	int selection=0;
    FILE *f_in;
	char store1[15]="lambton";
	char store2[15]="callaghan";
	char cancel[10]="cancel";
	char STOREinput[15];
	char storeinput[15];
	char productinput[15];
	char coffee[10]="coffee";
	char chocolate[10]="chocolate";
	char tea[10]="tea";
	char cake[10]="cake";
	char pie[10]="pie";
    
while (true){


	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)
		  {
		  }
         
		  
		  if (selection == 2)/*Input data*/
		  { 
			  printf("INPUT DATA\n");

			  do{
				  printf("Please,input the name of the store:\n(type 'cancel' to return to the previous menu) >");
		          scanf("%s",&storeinput);
                  lower (storeinput);

				  
		          if(strcmp (storeinput,store1) ==0 ){/*Lambton*/
					        printf("Please, input the name of the product: >");
							scanf ("%s",productinput);
							lower (productinput);

							if (strcmp (productinput,cancel) ==0){
								break;

							}else if( strcmp (productinput,coffee) ==0){
								 ReadProduct(lambton.coffee);
								 printf("%f %f %f %f %f %f \n",lambton.coffee.demandrate,lambton.coffee.setupcost,lambton.coffee.unitcost,lambton.coffee.inventorycost,lambton.coffee.sellingprice); 
						    
							       }else if(strcmp (productinput,chocolate) ==0){
 									   ReadProduct(lambton.chocolate);
							              
							              }else if(strcmp (productinput,tea) ==0){
											  ReadProduct(lambton.tea);

							                      }else if(strcmp (productinput,cake) ==0){
													  ReadProduct(lambton.cake);

								                        }else if(strcmp (productinput,pie) ==0){
															ReadProduct(lambton.pie);

															

										             }



				  }else if( strcmp (storeinput,store2) ==0){ /*Callaghan*/
					  printf("Please, input the name of the product: >");
							scanf ("%s",productinput);
							lower (productinput);

							if (strcmp (productinput,cancel) ==0){
								break;

							}else if( strcmp (productinput,coffee) ==0){
								 ReadProduct(callaghan.coffee);
						    
							       }else if(strcmp (productinput,chocolate) ==0){
									   ReadProduct(callaghan.chocolate);
							              
							              }else if(strcmp (productinput,tea) ==0){
											  ReadProduct(callaghan.tea);

							                      }else if(strcmp (productinput,cake) ==0){
													  ReadProduct(callaghan.cake);

								                        }else if(strcmp (productinput,pie) ==0){
															ReadProduct(callaghan.pie);
												  }
				  
				        }else if( strcmp (storeinput,cancel) ==0){
								break;
				              
				              }else{
								  printf("No such store Found");
						       }
			   }while(true);
	      }
	      
		  
		  if (selection == 3)
		  {
	      }

	      
		  if (selection == 4)
		  {
	      }

	      
		  if (selection == 5)
		  {
	      }

	      
		  if (selection == 6)
		  {
	      }
	
	 }
	 



return(0);
}



void lower(char *storeinput){
	int i,z;
	z = strlen(storeinput);
	for(i=0;i<=z;i++){
			storeinput[i]=tolower(storeinput[i]);
	}
}

void ReadProduct(product_t &product){
  printf("Please, input the demand rate >");
  scanf("%d",&product.demandrate);
  printf("Please, input the setup cost >");
  scanf("%d",&product.setupcost);
  printf("Please, input the unit cost >");
  scanf("%d",&product.unitcost);
  printf("Please, input the inventory cost >");
  scanf("%d",&product.inventorycost);
  printf("Please, input the selling price >");
  scanf("%d",&product.sellingprice);
  printf("Please, input the number of weeks >");
  scanf("%d",&product.weeks);
}


that's what i have trimmed off !
its not giving some errors...
but in LINE 93 i tried to printf the values and but they are not printing !
so i guess somthing wrong in the code.. ?
anyone ?
anyone ?
You're reading into a double variable with a "%d" format. %d stands for decimal. You should use "%lf" for doubles instead.
Topic archived. No new replies allowed.