Searching array

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Searching array
# 1  
Old 01-11-2014
Searching array

I'am writing a program in C language and my code is working perfectly i just need to add a search to it ...
My code lets users add companies, and then display them on screen...
i would like to add a search that allows user to type company name and then displayall its info on the screen !!
THANK YOU IN ADVANCE



Code:
#include <stdio.h>
struct Company
{
char name[30];
int id;
int rev;
int debt;

};
int main(){
struct Company a[3],b[3];
FILE *fptr;
int i;
fptr=fopen("file.txt","wb");
for(i=0;i<3;++i)
{
fflush(stdin);
printf("Enter Company name: ");
gets(a[i].name);
printf("Enter id: ");
scanf("%d",&a[i].id);
printf("Enter revenue: ");
scanf("%d",&a[i].rev);
printf("Enter debt: ");
scanf("%d",&a[i].debt);
}
fwrite(a,sizeof(a),1,fptr);
fclose(fptr);
fptr=fopen("file.txt","rb");
fread(b,sizeof(b),1,fptr);
for(i=0;i<3;++i)
{
printf("Name: %s\nid: %d\nrevenue: %d\ndebt: %d",b[i].name,b[i].id,b[i].rev,b[i].debt);
}
fclose(fptr);
}

# 2  
Old 01-11-2014
When posting homework, you must use the template specified in the Homework Rules. Without the information showing us the assignment, the instructor, and information about the class and institution, we cannot help you with your homework!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash arrays: rebin/interpolate smaller array to large array

hello, i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N. for case 1, I want to stretch N to fit M arrayHuge H = (... (2 Replies)
Discussion started by: f77hack
2 Replies

2. Shell Programming and Scripting

Bash 3.2 - Array / Regex - IF 3rd member in array ends in 5 digits then do somthing...

Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help. pesudo code if == ENDSINFIVEINTS ]]; then do... (4 Replies)
Discussion started by: briandanielz
4 Replies

3. Shell Programming and Scripting

perl : searching for month and storing the date and time in an array

I am writing the code in perl. I have an array in perl and each variable in the array contains the data in the below format Now I need to check the below variable w.r.t system month I need to store the date and time(Tue Aug 7 03:54:12 2012) from the below data into file if contains only 'Aug'... (5 Replies)
Discussion started by: giridhar276
5 Replies

4. Shell Programming and Scripting

Grep: Searching with a regex that contains a variable from an array

I'm attempting to grep for lines formatted like this: grep -e '^\\",' Any suggestions as to why this isn't working? ---------- Post updated at 05:03 PM ---------- Previous update was at 04:17 PM ---------- This was my solution: grep -e '^\'\",' It's hard to read, but basically I... (4 Replies)
Discussion started by: AcerAspirant
4 Replies

5. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

6. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

7. Shell Programming and Scripting

PHP: Search Multi-Dimensional(nested) array and export values of currenly worked on array.

Hi All, I'm writing a nagios check that will see if our ldap servers are in sync... I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable so...eg...let take the single array... (1 Reply)
Discussion started by: zeekblack
1 Replies

8. Shell Programming and Scripting

Searching for array in large list of files

I tried to make the title/subject detailed, but well.. have to keep it short as well. I am wanting to take a large list of strings, and search through a large list of files to hopefully find numerous matches. I am not sure the quickest way to do this though. // List of files file1.txt... (2 Replies)
Discussion started by: Rhije
2 Replies

9. Shell Programming and Scripting

Searching array of arrays in perl

Suppose there are two arrays of arrays: @A = ( , , , ); @B = ( , , , , ); For each of $A, $A, $A..., I want to find the corresponding one in @B (match the letter, like $A eq $B), and print out both the second item, for example, $A and $B. How can I do this in perl? grep + map? Hope I... (1 Reply)
Discussion started by: zx1106
1 Replies

10. Programming

Creating an array to hold posix thread ids: Only dynamic array works

I am facing a strange error while creating posix threads: Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output. Snippet 1 This works: -------------- int *threadids; threadids = (int *) malloc (num_threads * sizeof(int)); ... (4 Replies)
Discussion started by: kmehta
4 Replies
Login or Register to Ask a Question