L
Les Coover
Here is input: 1 red 7, 2 blue 5, 3 blue 6, 4 blue 6 (commas
indicate different records, the fields for each record are ID, COLOR and
NUMBER)
The following source code reads the input and lists it as output, then gives
a count of the total number of records.
Can anyone tell me how to change the code to that it will list and give a
total count of only those recods where color = blue and number = 6?
/* str_test */
#include <stdio.h>
int main(void)
{
int id, number, count = 0;
char color[100];
if (scanf("%d %99s %d", &id, &color, &number) != 0){
count += +1;
printf("%d %s %d\n", id, color, number);
while (scanf("%d %99s %d", &id, &color, &number) != 0){
count += +1;
printf("%d %s %d\n", id, color, number);
}
}
printf("%s%d\n\n", " Count = ", count);
return 0;
}
Thanks,
Les
indicate different records, the fields for each record are ID, COLOR and
NUMBER)
The following source code reads the input and lists it as output, then gives
a count of the total number of records.
Can anyone tell me how to change the code to that it will list and give a
total count of only those recods where color = blue and number = 6?
/* str_test */
#include <stdio.h>
int main(void)
{
int id, number, count = 0;
char color[100];
if (scanf("%d %99s %d", &id, &color, &number) != 0){
count += +1;
printf("%d %s %d\n", id, color, number);
while (scanf("%d %99s %d", &id, &color, &number) != 0){
count += +1;
printf("%d %s %d\n", id, color, number);
}
}
printf("%s%d\n\n", " Count = ", count);
return 0;
}
Thanks,
Les