C language help URGENT !!!


 
Thread Tools Search this Thread
Top Forums Programming C language help URGENT !!!
# 1  
Old 01-11-2014
Code C language help URGENT !!!

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
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. UNIX for Dummies Questions & Answers

What language is this?

Hi, Just got handed this script set def = HLA_DR.pockets set data = DRB1_1501.dat foreach a ( 'cat $data | args 3 |sort -u' ) cat $def | xC | grep -v $a > $$.def cat $data | grep $a | args 1,2 > $a.dat set pseudo = `cat MHCDR_pseudo.dat | grep HLA | grep $a | args 2`... (8 Replies)
Discussion started by: lost
8 Replies

3. Programming

which language will be the best

Hello, Ive got to amke a script to calculate how many emails are in the servers mailbox, how many times each IP address appears in the mailbox and to search for keywords, tehn produce the results in HTML report. The thing is I dont know where to start and what the best language to use would be. ... (4 Replies)
Discussion started by: clueless
4 Replies

4. Programming

c language

is there any difference between "char*" and "char *" (1 Reply)
Discussion started by: amol munde
1 Replies

5. Programming

c programming language

Can someone enligten me on what below program does? I understand getchar and putchar.. but what is this program suppose to do? I try to put printf on it, but it shows nothing.. can someone explain to me what this program is suppose to do? It is reading something and assigning to c? so, if... (8 Replies)
Discussion started by: convenientstore
8 Replies

6. UNIX for Advanced & Expert Users

URGENT,URGENT- Need help tape drive installation

Hi, I am trying to attach tape drive to sun V890 running Solaris 9 on it. I have installed HBA(qlogic) in slot 1 of 0-8 slots and booted the system. I do not see HBAin prtdiag output. The tape drive is not attached to HBA. The tape drive I am going to attach is Sony AIT3. 1.How can I make... (3 Replies)
Discussion started by: sriny
3 Replies

7. UNIX for Dummies Questions & Answers

A different language to me!

Hi all, I'm glad there's a section called UNIX for dummies on this forum cause when it comes to UNIX, I am certainly a dummie. I honestly don't have a clue about 98% of the UNIX commands out there so forgive me if this is a really stupid question. I'm trying to set up a MySQL server on my Mac... (7 Replies)
Discussion started by: kguenther
7 Replies
Login or Register to Ask a Question