Laynetworks  
Web laynetworks.com Google
Home | Site Map | Tell a friends
Management Tutorials
Download
Tutorials
History
Computer Science
Networking
OS - Linux and Unix
Source Code
Script & Languages
Protocols
Glossary
IGNOU
Quiz
About Us
Contact Us
Feedback
 
Sign up for our Email Newsletter
 
Get Paid for Your Tech Turorials / Tips

 
Home > Source Code > Computer Fundamentals
Page : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Computer Fundamentals
 

/*
******************************************************
*
*
*QUE.: Write a Prg in C Whose input is a file containing a
* in C Language. The prg should output the Language i.e.
* Prg C of prg in the input file.
*
* © Lay Networks
******************************************************
*/

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <string.h>

 

#define and &&

#define or ||

#define not !

#define null NULL

 

FILE *initprog(int,char *a[]);

int StartPROC(FILE *),Proceed(char *);

 

char *keywords[]={"int","char","float","double","long","unsigned","signed","Void","if","case",
"asm","break","default","while","register","volatile","static","extern","auto","do","cdecl",
"far","huge","near","else","for","continue","interrupt","enum","typedef","struct","const",
"pascal","return","short","sizeof","union"};

 

int iothers;

char Tokens[]={"{}[]()\"\';<>"};

char *directives[]={"#iclude","#if","#endif","#else","#pragma","main("};

 

void main(int argc,char *argv[])

{

initprog(argc,argv);

}

FILE *initprog( int argc, char *argv[])

{

int i,iCR;

FILE *fp;

if (argc<=1)

{

printf("\aError : Missing File Name");

printf("\nSyntex : File <<Drive:\\path\\Fileneme>>.[C]....");

printf("\n\npath\t : Contains absolute/relative Position of c file");

printf("\nfile\t : The File Must be 8.3 FAT,FAT16 based file");

printf("\n\nNOTE : File Name Can\'t contain wildcard characters[*,?]");

TOP

 

exit(0);

}

else

{

fp= (FILE * ) malloc ( sizeof ( fp ) );

for (i=1;i<=argc-1;i++)

{

fp=fopen(argv[i],"r");

if (fp==null)

{

perror("Error");

continue;

}

iCR=StartPROC(fp);

if (iothers - iCR>=200)

{

printf("\n %s file is not C file",argv[i]);

iothers=0;

continue;

}

if (iCR>=3 and iCR<50)

printf("\nFile %s Could be C file",argv[i]);

else if(iCR>50)

printf("\n %s is C file",argv[i]);

else if(iCR<3)

printf("\n %s file is not a C file",argv[i]);

}

fclose(fp);

}

}

int StartPROC(FILE *fp)

{

char *line;

register int CRatio=0;

line = (char *) malloc(BUFSIZ);

TOP

while(not feof(fp))

{

fgets(line,BUFSIZ,fp);

CRatio+=proceed(line);

}

return CRatio;

}

int proceed (char *StrBunch)

{

register int ictr,icctr,iwctr,iLen;

int iDirecCtr=0,ikeyWCtr=0;

for(ictr=0;ictr<sizeof(directives)/2;ictr++)

if(strstr(StrBunch,directives[ictr])!=null)

{

if (strstr(directives[ictr],"main(") !=null)

iDirecCtr+=50;

else

iDirecCtr++;

}

else

iothers++;

 

for(ictr=0;ictr<sizeof(keywords)/2;ictr++)

if (strstr(StrBunch,keywords[ictr])!=null)

ikeyWCtr++;

else

iothers++;

for(ictr=0;ictr<sizeof(Tokens)-1;ictr++)

if (strchr(StrBunch,Tokens[ictr])!=null)

ikeyWCtr++;

else

iothers++;

iothers-=ikeyWCtr+ikeyWCtr+iDirecCtr;

return ikeyWCtr+ikeyWCtr+iDirecCtr;

TOP
Page : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
   
Donation | Useful links | Link to Laynetworks.com | Legal
Copyright © 2000-2010 Lay Networks All rights reserved.