Programs Done In Nalco

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Programs Done In Nalco as PDF for free.

More details

  • Words: 1,702
  • Pages: 21
DATE: 11-12-06 TO 10-01-07 //"DICTIONARY.C" FOR CHECKING WORDS PRESENT IN THE DICTIONARY //IT GIVES AVAILABILITY OF WORD IN THE DICTIONARY //USAGE OF TEXT FILE TO STORE THE WORDS "DWORD.TXT" #include<stdio.h> #include #include<string.h> #include #include struct clist { char name[20]; struct clist *link; }; struct clist *a[26]; main() { int sflag,l; char country[20],ch; FILE *fp; clrscr(); fp=fopen("DWORD.TXT","r+"); printf("loading..."); if(fp==NULL) { puts("\n Unable to open the file"); exit(); } while(fgets(country,20,fp)) { l=strlen(country); country[l-1]='\0'; addtolist(toupper(country[0])-65,country); } while(1) { printf("\n Enter the word to search: "); fflush(stdin); gets(country); sflag=search_list(toupper(country[0])-65,country); if(sflag) printf("\n %s is present in the list\n",country); else

printf("\n Not present\n"); printf("\n Any more to search(y/n): "); fflush(stdin); ch=getch(); if(tolower(ch)!='y') break; } fclose(fp); return 0; } addtolist(int index,char *str) { char name[20]; struct clist *q,*r,*temp; temp=q=a[index]; r=malloc(sizeof(struct clist)); strcpy(r->name,str); //if list is empty if(q==NULL||strcmp(q->name,str)>0) { q=r; q->link=temp; a[index]=q; } else { //traverse the list while(temp!=NULL) { if(strcmp(temp->name,str)<=0 && (strcmp(temp->link->name,str)>0)||(temp>link==NULL)) { r->link=temp->link; temp->link=r; return; } temp=temp->link; } r->link=NULL; temp->link=r; } } search_list(int index,char *str) { struct clist *p; p=a[index]; if(p==NULL) return 0;

else { while(p!=NULL) { if(strcmp(p->name,str)==0) return 1; else p=p->link; } getch(); return 0; } } //PERMUTATION PROGRAM TO PERMUTATE THE GIVEN STRING #include <stdio.h> #include <stdlib.h> #include "data.h" #include "stack.h" static void Perm(unsigned n); static int count = 0; int main() { unsigned n;// = ParseCmdLine(argc, argv); int i; printf("\nEnter a string : "); gets(data); n=strlen(data); InitializeData(n); printf("\nThe characters are : "); for(i=0;i
void Perm(unsigned n) { unsigned item; if ( n == 0 ) { PrintStack(); ++count; return; } for ( item = 0; item < n; ++item ) { Push(RemoveItem(item)); Perm(n-1); InsertItem(Pop(), item); } } //ITS THE PROGRAM WHICH USES FILE CONCEPT OF STORING DATA IN A FILE /*--------- library management---------*/ #include<stdio.h> #include #include<string.h> #include #include #include struct clist { char name[20]; struct clist *link; }; struct clist *a[26]; main() { int ch; clrscr(); printf("\t\t***********MENU**********\t"); begin: printf("\nEnter the choice"); printf("\n\t 1. New member account"); printf("\n\t 2. Book information"); printf("\n\t 3. Member info"); printf("\n\t 4. Book availability"); printf("\n\t 5. Quit"); printf("\n\n\tChoice: "); scanf("%d",&ch);

switch(ch) { case 1: libmain(); goto begin; case 2: bkinfo(); goto begin; case 3: { int sflag,l; char country[20],ch; FILE *fp; clrscr(); fp=fopen("NAME.TXT","r"); if(fp==NULL) { puts("\n Unable to open the file"); exit(); } /*while(fgets(country,20,fp)) { l=strlen(country); country[l-1]='\0'; addtolist(toupper(country[0])-65,country); } */ while(1) { printf("\n Enter the member to search: "); fflush(stdin); gets(country); sflag=search_list((country[0])-65,country); if(sflag) printf("\n %s is a member\n",country); else printf("\n Not a member\n"); printf("\n Any more members to search(y/n): "); fflush(stdin); ch=getche(); if(tolower(ch)!='y') break; } fclose(fp); } goto begin; case 4:

{ int sflag,l; char country[20],ch; FILE *fp; clrscr(); fp=fopen("BKNM.TXT","r+"); if(fp==NULL) { puts("\n Unable to open the file"); exit(); } /*while(fgets(country,20,fp)) { l=strlen(country); country[l-1]='\0'; addtolist((country[0])-65,country); } */ while(1) { printf("\n Enter the book to search: "); fflush(stdin); gets(country); sflag=search_list((country[0])-65,country); if(sflag) printf("\n %s-- book is present\n",country); else printf("\nBook not present\n"); printf("\n Any more books to search(y/n): "); fflush(stdin); ch=getch(); if(tolower(ch)!='y') break; } fclose(fp); } goto begin; case 5: break; default: break; } return 0; } libmain() {

FILE *fp,*fs,*fn,*fi; int j,q; char ch,ch1,id[10],name[50],name1[50],name2[50],name4[50]; char address[100],first[50]; clrscr(); fp=fopen("MEMBER2.TXT","r+"); if(fp==NULL) { puts("\n Cannot open the file...."); exit(); } printf("\n\n\n\t\t LIBRARY MANAGEMENT \t\n\n"); again: { puts(""); gets(name); n1: puts("\nEnter FIRST name: "); gets(name1); fn=fopen("NAME.TXT","r+"); if(strlen(name1)==0) { puts("\nEnter the name field"); goto n1; } fputs("\n",fn); fputs(name1,fn); fputs("\n\n--------\nNAME: ",fp); fputs(name1,fp); fclose(fn); n2: puts("\nEnter LAST name: "); gets(name2); if(strlen(name2)==0) { puts("\n Enter the name field"); goto n2; } fputs(" ",fp); fputs(name2,fp); n3: puts("\nEnter I.D: "); gets(id); if(strlen(id)==0) { puts("\nID field was empty,plz enter the field"); goto n3; } fputs("\nMEMBER I.D: ",fp); fputs(id,fp);

n4:

printf("\nEnter address: "); gets(address); if(strlen(address)==0) { puts("\nADDRESS field was empty,plz enter the field"); goto n4; } fputs("\nADDRESS: ",fp); fputs(address,fp);

} fclose(fp); printf("\n stored in the file"); /*copying the file frm member to member1*/ fp=fopen("MEMBER2.TXT","a+"); if(fp==NULL) { puts("\n Cannot open the source file(create a new file and then run the program)"); exit(); } fs=fopen("MEMBER4.TXT","a+"); if(fs==NULL) { puts("\n Cannot open the target file(create a new file and then run the program)"); goto closing; } while(1) { ch=fgetc(fp); if(ch == EOF) goto closing; else fputc(ch,fs); } closing: fclose(fs); fclose(fp); getch(); return 0; } search_list(int index,char *str) { struct clist *p; p=a[index]; if(p==NULL) return 0; else

{ while(p!=NULL) { if(strcmp(p->name,str)==0) return 1; else p=p->link; } getch(); return 0; } } bkinfo() { FILE *fp,*fs,*fb; int ch; char q[10]; char name[10],bid[50],rid[50],bpur[20],blang[50],bname[100],bcat[80],baut[50]; clrscr(); clrscr(); fp=fopen("BK1.TXT","r+"); if(fp==NULL) { puts("\n Cannot open the file...."); exit(); } printf("\n\n\n\t\t BOOK INFORMATION \t\n\n"); again: puts(""); gets(name); fputs("\n--------",fp); fputs("\nBook id: ",fp); n1: printf("\nEnter book id: "); gets(bid); if(strlen(bid)==0) { puts("\nEnter the field"); goto n1; } fputs(bid,fp); n2:

fputs("\t\t Rack id: ",fp); printf("\nEnter rack id: "); gets(rid); if(strlen(rid)==0) {

puts("\nEnter the field"); goto n2; } fputs(rid,fp); n3:

n4:

n5:

n6:

fputs("\nbk_lang: ",fp); printf("\nEnter book language: "); gets(blang); if(strlen(blang)==0) { puts("\nEnter the field"); goto n3; } fputs(blang,fp); fb=fopen("BKNM.TXT","a+"); fputs("\nbk_name: ",fp); printf("\nEnter book name: "); gets(bname); if(strlen(bname)==0) { puts("\nEnter the field"); goto n4; } fputs(bname,fb); fputs(bname,fp); fclose(fb); fputs("\nbk_category: ",fp); printf("\nEnter book catagory: "); gets(bcat); if(strlen(bcat)==0) { puts("\nEnter the field"); goto n5; } fputs(bcat,fp); fputs("\nbk_author: ",fp); printf("\nEnter authors name: "); gets(baut); if(strlen(baut)==0) { puts("\nEnter the field"); goto n6; } fputs(baut,fp);

fputs("\nbk_purchase: ",fp); n7: printf("\nDate of purchase: "); //today=getdate(); //puts(today); //fputs(today,fp); /*if(strlen(bpur)==0) { puts("\nEnter the field"); goto n7; } fputs(bpur,fp); } */ fclose(fp); printf("\n stored in the file"); /*copying the file frm bk1 to bk2*/ fp=fopen("BK1.TXT","a+"); if(fp==NULL) { puts("\n Cannot open the source file(create a new file and then run the program)"); exit(); } fs=fopen("BK2.TXT","a+"); if(fs==NULL) { puts("\n Cannot open the target file(create a new file and then run the program)"); goto closing; } while(1) { ch=fgetc(fp); if(ch == EOF) goto closing; else fputc(ch,fs); } closing: fclose(fs); fclose(fp); getch(); return 0; } // A menu driven program for database management(linker) //USAGE OF DAT FILES FOR MANIPULATIONS..FULLY COMPLETED VERSION //HAS LISTING PROBLEM IN IT

#include<stdio.h> #include #include "lbr.c" #include "lbr1.c" main() { char choice; clrscr(); cls(); beg: printf("\n\n LIBRARY MANAGEMENT"); printf("\n\n 1.MEMBER AREA"); printf("\n\n 2.BOOK AREA"); printf("\n\n 3.EXIT"); printf("\n\n ENTER CHOICE: "); choice=getche(); clrscr(); switch(choice) { case '1':goto main1; case '2':goto main2; case '3': printf("\n THANK YOU"); printf("\n press any key to exit"); getch(); exit(); default:goto beg; } main1: { FILE *fp,*ft,*fq; char another,choice; struct emp { char name[60]; int age; int id; char address[100]; }; struct emp e; char empname[40]; long int recize; int a; fp=fopen("EMP.DAT","rb+"); if(fp==NULL) { fp=fopen("EMP.DAT","wb+");

if(fp==NULL) { puts("\n Cannot open the file"); exit(); } } recize=sizeof(e); while(1) { cls(); //printf("MEMBER AREA"); gotorc(2,10); printf("1. ADD MEMBER"); gotorc(3,10); //printf("2. LIST MEMBERS"); //gotorc(4,10); printf("2. MODIFY MEMBER"); gotorc(4,10); printf("3. DELETE MEMBER"); gotorc(5,10); printf("4. EXIT"); gotorc(7,10); printf(" ENTER YOUR CHOICE: "); fflush(stdin); choice=getche(); switch(choice) { case '1': fseek(fp,0,SEEK_END); another='Y'; while(another=='Y'|| another=='y') { //fq=fopen("MEMBERINFO.TXT","a+"); printf("\n"); printf(" Name: "); gets(e.name); //fputs(e.name,fq); printf("\n Age: "); scanf("%d",e.age); //fprintf(e.age,fq); printf("\n I.D: "); scanf("%d",e.id); //fprintf(e.id,fq); printf("\n Address: "); gets(e.address);

//fputs(e.address,fq); printf(""); scanf("%d",a); fwrite(&e,recize,1,fp); //fclose(fq); printf("\n ADD ANOTHER MEMBER: "); fflush(stdin); another=getche(); } break; /*case '2': rewind(fp); while(fread(&e,recize,1,fp)==1) printf("\n %s %d",e.name,e.id); puts(e.name); printf("\t\b,"); printf("%d",e.age); printf("\t\b,"); printf("%d",e.id); printf("\t\b,"); puts(e.address); break;*/ case '2': another='Y'; while(another=='Y'|| another=='y') { printf("\n Enter name of the member to modify"); gets(empname); rewind(fp); while(fread(&e,recize,1,fp)==1) { if(strcmp(e.name,empname)==0) { //fq=fopen("MEMBERMOD.TXT","a+"); printf("\n Enter new name: "); gets(e.name); //fputs(empname,fq); //fputs("---modified as--- ",fq); //fputs(e.name,fq); printf("\n Enter new age: "); scanf("%d",e.age); printf("\n Enter new ID: "); scanf("%d",e.id); printf("\n Enter new address: "); gets(e.address); printf(""); scanf("%d",a); goto dot;

} } dot: printf("\n\n Modify another record: "); fflush(stdin); another=getche(); } break; case '3': another='y'; while(another=='y'|| another=='Y') { printf("\n Enter member name to delete: "); gets(empname); ft=fopen("TEMP.DAT","wb"); rewind(fp); { while(fread(&e,recize,1,fp)==1) { if(strcmp(e.name,empname)!=0) fwrite(&e,recize,1,ft); } fclose(fp); fclose(ft); remove("EMP.DAT"); rename("TEMP.DAT","EMP.DAT"); printf("Member deleted"); } fp=fopen("EMP.DAT","rb+"); printf("\n Delete another member: "); fflush(stdin); another=getche(); } break; case '4': fclose(fp); goto beg; } } } main2: { FILE *fp,*ft,fe; char another,choice; struct emp1 { char name[40]; char category[40];

char author[40]; int id; int rid; char language[100]; }; struct emp1 e1; char empname[40]; long int recize; int a,q,w; fp=fopen("EMP1.DAT","rb+"); if(fp==NULL) { fp=fopen("EMP1.DAT","wb+"); if(fp==NULL) { puts("\n Cannot open the file"); exit(); } } recize=sizeof(e1); while(1) { cls1(); //printf("BOOK AREA"); gotorc1(2,10); printf("1. ADD BOOK"); gotorc1(3,10); //printf("2. LIST BOOKS"); //gotorc1(4,10); printf("2. MODIFY BOOK INFO"); gotorc1(4,10); printf("3. ISSUE BOOK"); gotorc1(5,10); printf("4. EXIT"); gotorc1(7,10); printf(" ENTER YOUR CHOICE: "); fflush(stdin); choice=getche(); switch(choice) { case '1': fseek(fp,0,SEEK_END); another='Y';

while(another=='Y'|| another=='y') { //fe=fopen("BOOKINFO.TXT","a+"); printf("\n"); printf(" Book name: "); gets(e1.name); //fputs(e1.name,fe); printf("\n Book i.d: "); scanf("%d",e1.id); //fputs(e1.id,fe); printf("\n Authors name: "); gets(e1.author); //fputs(e1.author,fe); printf(""); scanf("%d",&q); //printf("\n Rack i.d: "); //scanf("%d",&q); //scanf("%d",e1.rid); //scanf("%d",&q); printf("\n Book Category: "); gets(e1.category); //fputs(e1.category,fe); printf(""); scanf("%d",&w); printf("\n Book Language: "); gets(e1.language); //fputs(e1.language,fe); scanf("%d",&q); fwrite(&e1,recize,1,fp); //fclose(fe); printf("\n ADD ANOTHER BOOK: "); fflush(stdin); another=getche(); } break; /*case '2': rewind(fp); while(fread(&e,recize,1,fp)==1) printf("\n %s %d",e.name,e.id); puts(e.name); printf("\t\b,"); printf("%d",e.age); printf("\t\b,"); printf("%d",e.id); printf("\t\b,"); puts(e.address); break;*/ case '2':

another='Y'; while(another=='Y'|| another=='y') { printf("\n Enter name of the book to modify:"); gets(empname); rewind(fp); while(fread(&e1,recize,1,fp)==1) { if(strcmp(e1.name,empname)==0) { //fe=fopen("BOOKMOD.TXT","a+"); printf("\n Enter new book name: "); gets(e1.name); //fputs(empname,fe); //fputs("---modified as---",fe); //fputs(e1.name,fe); printf("\n Enter new rack id: "); scanf("%d",e1.id); /*printf("\n Enter new ID: "); scanf("%d",e.id); printf("\n Enter new address: "); gets(e.address); printf(""); scanf("%d",a);*/ } } printf("\n\n Modify another record: "); fflush(stdin); //fclose(fe); another=getche(); } break; case '3': another='y'; while(another=='y'|| another=='Y') { printf("\n Enter book name to ISSUE: "); gets(empname); ft=fopen("TEMP1.DAT","wb"); rewind(fp); while(fread(&e1,recize,1,fp)==1) { if(strcmp(e1.name,empname)!=0) fwrite(&e1,recize,1,ft); } fclose(fp); fclose(ft);

remove("EMP1.DAT"); rename("TEMP1.DAT","EMP1.DAT"); fp=fopen("EMP1.DAT","rb+"); printf("\n ISSUE another book: "); fflush(stdin); another=getche(); } break; case '4': fclose(fp); goto beg; } } } } //WRITE TO FILE #include<stdio.h> #include main() { FILE *fp; char s[80]; clrscr(); fp=fopen("POEM.TXT","w"); if(fp==NULL) { puts("canot open the file"); exit(); } printf("\nEnter name:"); gets(s); while(strlen(get(s))>0); { fputs(s,fp); fputs("\n",fp); } fclose(fp); getch(); return 0; } /*program to append the usage of SPRINTF AND SSCANF*/ #include<stdio.h>

#include main() { { int i=10 ; char ch='A'; float a=3.14; char str[20]; clrscr(); printf("\n%d%c%f",i,ch,a); sprintf(str,"%d%c%f",i,ch,a); /*it store the information in the array str*/ printf("\n%s",str); /*prints the array in the str*/ getch(); return 0; } /*illustrates the working of puts() and gets()*/ #include<stdio.h> #include main() { char f[40]; clrscr(); puts("enter name: "); gets(f); puts("HAPPY FOOTBALLING"); puts(f); getch(); return 0; } /*illustrates the working of putchar(),putch(),fputchar()*/ #include<stdio.h> #include main() { char ch='A'; putch(ch); putchar(ch); fputchar(ch); putch('Z'); putchar('z'); fputchar('z'); return 0; }

/*illustrates the usage of the functions getch(),getche(), fgetchar(),getchar()*/ #include<stdio.h> #include main() { char ch; printf("\n enter any key to continue:"); getch(); printf("\n enter any character"); /*no need of enter 4 goin 2 the next row*/ ch=getche(); printf("\n type the character"); getchar(); printf("\n continue"); fgetchar(); return 0; }

Related Documents

Programs Done In Nalco
November 2019 10
Done
November 2019 44
Programs
October 2019 61
Training Programs In Lcp
December 2019 35