Sponsored Content
Full Discussion: Searching array
Homework and Emergencies Homework & Coursework Questions Searching array Post 302883182 by aloushi on Saturday 11th of January 2014 02:25:33 PM
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);
}

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
hx509 enviroment functions(3)					Heimdalx509library				     hx509 enviroment functions(3)

NAME
hx509 enviroment functions - Functions int hx509_env_add (hx509_context context, hx509_env *env, const char *key, const char *value) int hx509_env_add_binding (hx509_context context, hx509_env *env, const char *key, hx509_env list) const char * hx509_env_lfind (hx509_context context, hx509_env env, const char *key, size_t len) const char * hx509_env_find (hx509_context context, hx509_env env, const char *key) hx509_env hx509_env_find_binding (hx509_context context, hx509_env env, const char *key) void hx509_env_free (hx509_env *env) Detailed Description Function Documentation int hx509_env_add (hx509_context context, hx509_env * env, const char * key, const char * value) Add a new key/value pair to the hx509_env. Parameters: context A hx509 context. env enviroment to add the enviroment variable too. key key to add value value to add Returns: An hx509 error code, see hx509_get_error_string(). int hx509_env_add_binding (hx509_context context, hx509_env * env, const char * key, hx509_env list) Add a new key/binding pair to the hx509_env. Parameters: context A hx509 context. env enviroment to add the enviroment variable too. key key to add list binding list to add Returns: An hx509 error code, see hx509_get_error_string(). const char* hx509_env_find (hx509_context context, hx509_env env, const char * key) Search the hx509_env for a key. Parameters: context A hx509 context. env enviroment to add the enviroment variable too. key key to search for. Returns: the value if the key is found, NULL otherwise. hx509_env hx509_env_find_binding (hx509_context context, hx509_env env, const char * key) Search the hx509_env for a binding. Parameters: context A hx509 context. env enviroment to add the enviroment variable too. key key to search for. Returns: the binding if the key is found, NULL if not found. void hx509_env_free (hx509_env * env) Free an hx509_env enviroment context. Parameters: env the enviroment to free. const char* hx509_env_lfind (hx509_context context, hx509_env env, const char * key, size_t len) Search the hx509_env for a length based key. Parameters: context A hx509 context. env enviroment to add the enviroment variable too. key key to search for. len length of key. Returns: the value if the key is found, NULL otherwise. Version 1.5.2 11 Jan 2012 hx509 enviroment functions(3)
All times are GMT -4. The time now is 02:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy