473,412 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Need help with a print statement using arrays and structs

29
Expand|Select|Wrap|Line Numbers
  1. int search(student_record db[], int count)
  2. {
  3.     int i;
  4.     char fname[30], lname[30];
  5.     printf("Enter the employees first name:\n");
  6.     scanf("%s",fname);
  7.     printf("Enter the employees last name:\n");
  8.     scanf("%s",lname);
  9.     printf("\n\n");
  10.  
  11.     for(i=0; i<count; i++)
  12.     {
  13.         if((strcmp(fname,db[i].firstname)==0) && (strcmp(lname,db[i].lastname)==0))
  14.         {
  15.             printf("Record Found!\n");
  16.             printf("Record[%d] = %s %s %s %s %s %s %s \n\n", i ,db[i].firstname,db[i].lastname,db[i].ssno,db[i].city,db[i].state,db[i].year,db[i].sex);
  17.             return i;
  18.         }
  19.         return -1;
  20.     }
  21. }
This will find a record in my database but when it prints it will print the first element in the array. Which makes sense because on this line:
Expand|Select|Wrap|Line Numbers
  1. printf("Record[%d] = %s %s %s %s %s %s %s \n\n", i ,db[i].firstname,db[i].lastname,db[i].ssno,db[i].city,db[i].state,db[i].year,db[i].sex);
it is using the variable of i as 0. I just need it to be able to print the record taht it found.
Nov 7 '06 #1
2 1537
dru
29
Just moving it to the top to make sure it doesnt get missed.
Nov 7 '06 #2
dru
29
Anyone got an idea?
Nov 7 '06 #3

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

Similar topics

5
by: Dariusz | last post by:
I want to use arrays in my website (flat file for a guestbook), but despite having read through countless online tutorials on the topic, I just can't get my code to work. I know there are...
8
by: cpptutor2000 | last post by:
I am using an STL list to store data packets in a network simulator. The data packets are really C structs, which have other C structs inside them. These structs contain unsigned char arrays of...
5
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;
61
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...
1
by: rllioacvuher | last post by:
I need help with a program. I have implemented that following header file with an unordered list using one array, but i need to be able to use an ordered list and 2 arrays (one for the links and one...
7
by: Francois Grieu | last post by:
Hello, is the size of a type, defined using typedef as a collection of arrays of unsigned char, the sum of the size of the arrays ? After simplifying my question, it probably is equivalent to:...
11
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....
12
by: rajash | last post by:
Thanks to everyone on this forum for their helpful comments, now here is my solution to Exercise 1.17, pretty short and neat! // print lines longer than 80 chars char x; // allocate buffer ...
127
by: sanjay.vasudevan | last post by:
Why are the following declarations invalid in C? int f(); int f(); It would be great if anyone could also explain the design decision for such a language restricton. Regards, Sanjay
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.