Created
March 27, 2013 05:29
-
-
Save mnive93/5251920 to your computer and use it in GitHub Desktop.
macro processor in c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<conio.h> | |
#include<string.h> | |
int number=0; | |
struct table | |
{ | |
char data[100]; | |
char val[20]; | |
}t[10]; | |
int main() | |
{ | |
FILE *fp,*fp1; | |
fp=fopen("input.txt","r"); | |
fp1=fopen("output.txt","w"); | |
int flag=0,i; | |
char s[100],ch,s1[100],s2[100],s3[100],line[100]; | |
char *temp; | |
if(fp<0) | |
printf("\nFile doesnot exists\n"); | |
else | |
{ | |
while(!feof(fp)) | |
{ | |
fgets(line , sizeof(line),fp); | |
strcpy(s3,line); | |
temp=strtok(line," ;"); | |
if(strcmp(temp,"#define")==0) | |
{ | |
sscanf(s3,"%s %s %s",s,s1,s2); | |
strcpy(t[number].data,s1);//s1 will have EQ | |
strcpy(t[number].val,s2);//s2 will have == | |
number+=1;//storing it in a structure! | |
printf("%s\n",s3); | |
} | |
else | |
{ | |
while(temp!=NULL) | |
{ | |
for(i=0;i<number;i++) | |
{ | |
if(strcmp(t[i].data,temp)==0) // to compare whether the word is equal to the words in the structure | |
{ | |
flag=1; //settin flag=1 to print the val given for this word | |
break; | |
} | |
} | |
if(flag!=1) | |
{ | |
printf("%s ",temp);//if flag!=1 then it will chuma print the word | |
} | |
else | |
{ | |
printf("%s ",t[i].val);//else it will print its respective value | |
flag=0; | |
} | |
temp= strtok(NULL," ;"); //this is used to separate the string according to space or ; | |
} | |
printf("\n"); | |
} | |
} | |
} | |
getch(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment