TEXT EDITOR #include<stdio.h> #include<conio.h> #include<ctype.h> #include<dos.h> #include<iostream.h> #include<fstream.h> char filename[15]; char buff[1000]; int count; void main() { char ch,c; ofstream outfile; ifstream infile; clrscr(); cout<<"\n"; cout<<"######################################"; cout<<"\n TEXT EDITOR \n"; cout<<"######################################"; cout<<"\n Type ur text and then press escape key\n"; while(c!=27) { c=getch(); switch(c) { case 0: printf(""); buff[count++]='\n'; break; case 1: buff[count++]='\n'; break; default: cprintf("%c",c); } buff[count++]=c; } cprintf("\n\n Do u want to save?(y/n)"); scanf("%s",&c); if((c=='Y')||(c=='y')) { cprintf("\n Enter the filename with extension is & chara only :");
39
Embed
prasanthmani.files.wordpress.com€¦ · Web view#include #include #include #include #include #include
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
TEXT EDITOR
#include<stdio.h>#include<conio.h>#include<ctype.h>#include<dos.h>#include<iostream.h>#include<fstream.h>char filename[15];char buff[1000];int count;void main(){char ch,c;ofstream outfile;ifstream infile;clrscr();cout<<"\n";cout<<"######################################";cout<<"\n TEXT EDITOR \n";cout<<"######################################";cout<<"\n Type ur text and then press escape key\n";while(c!=27){c=getch();switch(c){case 0:printf("");buff[count++]='\n';break;case 1:buff[count++]='\n';break;default:cprintf("%c",c);}buff[count++]=c;}cprintf("\n\n Do u want to save?(y/n)");scanf("%s",&c);if((c=='Y')||(c=='y')){cprintf("\n Enter the filename with extension is & chara only :");scanf("%s",&filename);outfile.open(filename,ios::in);outfile<<buff;outfile.close();cout<<"\n Do u want to open ?(y/n);"<<"\n";
ch=getch();{if((ch=='Y')||(ch=='y')){cprintf("\n Enter the filenme to open:");scanf("%s",&filename);infile.open(filename,ios::in);infile.get(buff,count,'*');printf("%s",buff);getch();infile.close();}}}}
if((strcmp(op.mnem,res.instr))==0){resadd1=res.add;strcpy(resopc,op.opcode);}}while(!feof(opcode));rewind(opcode);do{fscanf(symbol,"%s%d",sym.symb,&sym.symadd);if((strcmp(res.oper,sym.symb))==0){ressymadd=sym.symadd;}}while(!feof(symbol));rewind(symbol);fprintf(object,"%s%10d%10s%10d\n",res.instr,resadd1,resopc,ressymadd);}}while(!feof(result));printf("pass 2 is completed");getch();}
INPUT FILES
J5RESULT.TXT
0 NULL START 200200 A DS 100300 B DC 5 301 NULL READ A304 NULL READ B307 NULL PRINT A310 NULL STOP NULL313 NULL END NULL
#include<stdio.h>#include<conio.h>#include<string.h>#include<stdlib.h>struct object_code{int locctr;char add[10];}obcode[300];void main(){char input[100][16],output[100][16],binary[20],address[20],stloc[10];int len,bitmask,loc,tlen=0,tloc,textloc,i=0,location,j,k,count=0,start,n,num=0,inc=0;FILE *fp1,*fp2;clrscr();fp1=fopen("inputrel.txt","r");fp2=fopen("loadout.txt","w");printf("Enter location where program hasn to be loaded: ");scanf("%s",stloc);start=atoi(stloc);location=start;tloc=start;fscanf(fp1,"%s",input[i]);while(strcmp(input[i],"T")!=0){strcpy(output[i],input[i]);i++;fscanf(fp1,"%s",input[i]);strcpy(output[i],input[i]);}itoa(start,output[2],10);while(strcmp(input[i],"E")!=0){strcpy(output[i],input[i]);if(strcmp(input[i],"T")==0){for(j=0;j<3;j++){i++ ;fscanf(fp1,"%s",input[i]);strcpy(output[i],input[i]);
SYMBOL TABLE#include<stdio.h>#include<conio.h>#include<string.h>void main(){char s[20];int add=100;FILE *fp;clrscr();fp=fopen("input.txt","r");rewind(fp);do{fscanf(fp,"%s",s);if(strcmp(s,"int")==0){while(strcmp(s,";")!=0){fscanf(fp,"%s",s);if((strcmp(s,";")!=0)&&(strcmp(s,",")!=0)){printf("%d\t%s\t%s\t%d\n",add,"int",s,sizeof(int));add+=2;}}}else if(strcmp(s,"float")==0){while (strcmp(s,";")!=0){fscanf(fp,"%s",s);if((strcmp(s,";")!=0)&&(strcmp(s,",")!=0)){printf("%d\t%s\t%s\t%d\n",add,"float",s,sizeof(float));add+=4;}}}}while(!feof(fp));fclose(fp);getch();}
INPUT FILE:
INPUT.TXT
int a , b ;float c , d ;
OUTPUT:
MACRO PROCESSOR
#include<stdio.h>#include<conio.h>#include<string.h>#include<stdlib.h>void main(){char n1,n,c1,i;char fn[10][10],ilab[20],iopd[20],m[20][3],oper[20],opd[20];FILE *fp1,*fp2,*p[5];clrscr();n=0;fp1=fopen("macst.txt","r");while(!feof(fp1)){fscanf(fp1,"%s%s%s\n",ilab,iopd,oper);if(strcmp(iopd,"macro")==0)n++;}printf("number of macro=%d\n",n);n1=n;printf("Enter the text filename\n");for(i=0;i<n;i++){scanf("%s",fn[i]);p[i]=fopen(fn[i],"w");}n=0;rewind(fp1);while(!feof(fp1)){fscanf(fp1,"%s%s%s\n\t",ilab,iopd,oper);if(strcmp(iopd,"macro")==0){strcpy(m[n],oper);fscanf(fp1,"%s%s%s\n\t",ilab,iopd,oper);while(strcmp(iopd,"mend")!=0){