473,513 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Structs

6 New Member
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
May 6 '07 #1
1 920
baron06
6 New Member
Do you mean when you enter JOE,joe,JOe...etc., you want the program should find the "joe" struct???

Therefore you can convert the input to lowercase, iterate over the struct array
and use strcmp(); if the input and the struct's name attribute is equal or not...
May 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1985
by: news.microsoft.com | last post by:
Hi, I am using structs and am also using property accessors to access those private member fields... TO me this is a good way of handling them, but I find alot of people using direct access to...
6
1682
by: James Pascoe | last post by:
Dear All, Apologies if this is OT. I have a C program which processes an arbitrary number of structs that are stored in a hash table. (The nature of the processing and the layout of the...
5
3113
by: Paminu | last post by:
Why make an array of pointers to structs, when it is possible to just make an array of structs? I have this struct: struct test { int a; int b;
10
2055
by: Angel | last post by:
I'm using several C functions (in a dll) that receive a struct as parameter. Since I'm doing it in C#, I assume I need to recreate the struct in C# in order to call the function with the required...
5
2755
by: Bidule | last post by:
Hi, I'm trying to sort structs defined as follows: struct combinationRec { float score; char* name; }; The number of structs and the length of the "name" field are not known
5
2890
by: Bilgehan.Balban | last post by:
Hi, I am currently brushing up my c++ knowledge and I would like to ask you about the differences between classes and C structs, in the function/method perspective. 1) Is it correct to say...
61
3691
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch...
11
2605
by: Cliff Martin | last post by:
Hi, I am reading a fairly large file a line at a time, doing some processing, and filtering out bits of the line. I am storing the interesting information in a struct and then printing it out....
29
2742
by: Dom | last post by:
I'm really confused by the difference between a Struct and a Class? Sometimes, I want just a group of fields to go together. A Class without methods seems wrong, in that it carries too much...
43
3771
by: JohnQ | last post by:
Are a default constructor, destructor, copy constructor and assignment operator generated by the compiler for a struct if they are not explicitely defined? I think the answer is yes, because...
0
7162
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.