Hi,
I'm trying to search the inputed data, using a second struct and printing the result if the two names match.
Eg i have entered
Joe BROWN 10/10/1000
Chris BROWN 10/10/1000
Joe BROWN 10/10/1000
Matt Brown 10/10/1000
then i enter JOE in the search string, and wish to scan the original struct for all joe's. However i have no idea how to do this, please if anyone could inform me on how to do this it would be great.
Below is the code i have already written:
//
//
//
#include <stdio.h>
#include <string.h>
#include <assert.h>
#define TRUE 1
#define FALSE 0
#define MAX_NAME_LEN 20
#define MAX_STUDENTS 21
typedef struct student Student;
struct student {
char first_name [MAX_NAME_LEN];
char last_name [MAX_NAME_LEN];
int birthyear;
int birthmonth;
int birthday;
};
typedef struct student1 Student1;
struct student1 {
char string_name [MAX_NAME_LEN];
};
int main (int argc, char **argv) {
int i = 0;
int j = 0;
int p = 0;
int keepReading = 1;
Student students [MAX_STUDENTS];
Student1 student1s [MAX_STUDENTS];
while (keepReading == TRUE && i < MAX_STUDENTS) {
if (keepReading == TRUE) {
printf ("Please enter your first name\n");
if (scanf ("%20s", students[i].first_name) == EOF) {
keepReading = FALSE;
}
}
if (keepReading == TRUE) {
printf("please enter your last name\n");
if (scanf ("%20s", students[i].last_name) == EOF) {
keepReading = FALSE;
}
}
if (keepReading == TRUE) {
printf("Please enter the day of your birth\n");
if (scanf ("%d", &students[i].birthday) == EOF) {
keepReading = FALSE;
}
}
if (keepReading == TRUE) {
printf("Please enter the month of your birth\n");
if (scanf ("%d", &students[i].birthmonth) == EOF) {
keepReading = FALSE;
}
}
if (keepReading == TRUE) {
printf("Please enter the year of your birth\n");
if (scanf ("%d", &students[i].birthyear) == EOF) {
keepReading = FALSE;
}
}
i++;
}
while(j < i - 1) {
printf("%s %s, was born on %d/%d/%d\n", students[j].first_name,students[j].last_name, students[j].birthday,students[j].birthmonth,students[j].birthyear);
j++;
}
int keepReading2 = 1;
while(keepReading2 == TRUE && p<21){
printf("Enter search string\n");
if (scanf ("%20s", student1s[p].string_name) == EOF) {
keepReading2 = FALSE;
}
p++;
}
return (0);
}
Advanced Thanks
Gilly