void LetUserSearchForStudent()I just made the function print the last and first name of the student when the ID matches. You can make it do whatever you want.
{
// Getting the ID from the user to search for
int id = GetIDFromUser();
int i;
for (i=0;i<10;i++) {
if (id==students[i].ID) {
printf("%s,%s\n", students[i].LastName, students[i].FirstName);
return;
}
printf("Student not found!\n");
}
Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

40 replies to this topic
#25
Posted 09 April 2010 - 02:00 PM
It should be pretty simple. Just loop through each student and check to see if the ID matches.
#26
Posted 09 April 2010 - 02:26 PM
Thanks alot. This really made me learn quite a few things about indexes and thats where i was mixing up.
In the program i was trying to find a way to update the file by searching for a particular file like u showed me just now. In another function could i call back that function then change an information from the data searched for?
In the program i was trying to find a way to update the file by searching for a particular file like u showed me just now. In another function could i call back that function then change an information from the data searched for?
#27
Posted 09 April 2010 - 02:32 PM
Yeah you should be able to do that.
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)
Download the new operating system programming kit! (some assembly required)
#28
Posted 09 April 2010 - 02:41 PM
ok..ill try it and post it later so u can direct me ok
#29
Posted 09 April 2010 - 08:46 PM
I tried this function but not gettin what i want. Could u say step by step what i need to do plz
void UpdateStudents(Student students[])
{
char name[10];
int position;
int change;
printf("Enter the First name of the person record you want to edit: ");
scanf("%d", &name);
for (int i=0;i<10;i++)
{
if (name==students[i].FirstName)
{
printf("Enter Index position of desired changes[0-6]:");
fflush(stdin);
scanf("%d", &position);
printf("What do you want to change it to:");
fflush(stdin);
scanf("%d", &change);
Student students[position]=change;
}
}
}
#30
Posted 09 April 2010 - 09:12 PM
scanf("%d", &name);This won't work because %d tells scanf to get an integer. name is a string, and the proper way to get a string is with fgets:
fgets(name, 10, stdin);
if (name==students[i].FirstName)In C, you can not compare to strings like this. To compare strings, you need to include the string.h file and use the strcmp function.
if (!strcmp(name, students[i].FirstName))
printf("Enter Index position of desired changes[0-6]:");I don't know what you are trying to do here, but it is definitely wrong. What is the user changing exactly? Why does the user need to choose an index position if they already input the first name?
fflush(stdin);
scanf("%d", &position);
printf("What do you want to change it to:");
fflush(stdin);
scanf("%d", &change);
Student students[position]=change;
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)
Download the new operating system programming kit! (some assembly required)
#31
Posted 09 April 2010 - 09:22 PM
What im trying to do is allow the user to change anything he wants from the record. Updating it if he wants to change a name, id number, dob etc...
#32
Posted 09 April 2010 - 09:39 PM
You are going to have to add the other options, but here is a head start:
Cprogramming.com Tutorial: Switch-case structure
int choice;If you need to, read up on the C switch statement:
printf("What do you want to change?\n");
printf("1. Change ID number\n");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Input new ID number: ");
scanf("%d", &students[i].ID);
break;
default:
printf("Bad input\n");
break;
}
Cprogramming.com Tutorial: Switch-case structure
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)
Download the new operating system programming kit! (some assembly required)
#33
Posted 09 April 2010 - 09:49 PM
Thank you very much..I am gonna finish up and post it
#34
Posted 09 April 2010 - 10:13 PM
What do u think abt this code
void UpdateStudents(Student students[])
{
char name[10];
int position;
int change;
printf("Enter the First name of the person record you want to edit: ");
scanf("%d", &name);
for (int i=0;i<10;i++)
{
if (strcmp(name,students[i].FirstName) == 0)
{
printf("Enter Index position of desired changes[0-6]:");
scanf("%d", &position);
printf("What do you want to change it to:");
switch(position)
{
case 0: scanf("%d",change_int);
student[i].id = change_int;
break;
case 1: scanf("%s",change_str);
strcpy(student.LastName,change_str);
break;
case 2: scanf("%s",change_str);
strcpy(student.FirstName,change_str);
break;
case 3: scanf("%d",change_int);
student[i].DateOfBirth = change_int;
break;
default: break;
}
}
#35
Posted 09 April 2010 - 10:20 PM
How can i write what the user change back to the file "record.txt"
void UpdateStudents(Student students[])
{
int choice;
for (int i=0;i<10;i++)
{
printf("What do you want to change?\n");
printf("1. Change ID number\n 2. Change Last Name\n 3. Change First Name\n 4. Change Date of Birth\n 5. Change Address\n 6. Change Telephone number\n 7. Change Program\n");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Input new ID number: ");
scanf("%d", &students[i].ID);
break;
case 2:
printf("Input new Last Name: ");
scanf("%d", &students[i].LastName);
break;
case 3:
printf("Input new First Name: ");
scanf("%d", &students[i].FirstName);
break;
case 4:
printf("Input new Date of Birth: ");
scanf("%d", &students[i].DateOfBirth);
break;
case 5:
printf("Input new Address: ");
scanf("%d", &students[i].Address);
break;
case 6:
printf("Input new Telephone Number: ");
scanf("%d", &students[i].TelephoneNumber);
break;
case 7:
printf("Input new Program: ");
scanf("%d", &students[i].ProgramPursued);
break;
default:
printf("Bad input\n");
break;
}
} }
#36
Posted 20 June 2010 - 02:31 AM
BUMP
does it work in c++ the same way?
does it work in c++ the same way?
Also tagged with one or more of these keywords: hello world, read, write, file
Language Forums →
C and C++ →
How to implement password access to specific file type in Linux/Windows programmatically?Started by Kosarar, 08 Jan 2017 ![]() |
|
![]() |
||
Language Forums →
Java →
[HOMEWORK] Error Reading Files to Store their Data in an ArrayStarted by bodette, 26 Nov 2015 ![]() |
|
![]() |
||
Tutorial Forums →
Other Programming Tutorials →
Mobile Development Tutorials →
Creating a file browser in AndroidStarted by farrell2k, 16 Mar 2015 ![]() |
|
![]() |
||
![]() |
Language Forums →
Databases →
Access 2007 error while running .mdb fileStarted by Crilevral, 24 Feb 2015 ![]() |
|
![]() |
|
Language Forums →
Java →
How to write console output to a fileStarted by Alcamech, 29 Jan 2015 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download