answersLogoWhite

0

//PROGRAM TO CHECK SYNTAX OF for STATEMENT

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<process.h>

void main()

{

FILE *fp1,*fp2;

char a[100],ch,b[50];

int col=0,i=0,bra1=0,bra2=0,flag=0;

clrscr();

fp1=fopen("c:\\file1.txt","w");

if(fp1==NULL)

{

printf("\n ERROR IN OPENING FILE ... ");

getch();

exit(0);

}

else

{

printf("\n ENTER THE for STATEMENT ... ");

gets(a);

fprintf(fp1,"%s",a);

for(i=0;i<3;i++)

b[i]=a[i];

b[i]=0;

if(strcmp(b,"for")!=0)

{

printf("\n ERROR: UNDEFINED SYMBOL for ");

getch();

exit(0);

}

if(a[i]=='(')

flag=1;

else

flag=0;

fclose(fp1);

fp1=fopen("c:\\file1.txt","r");

while(1)

{

ch=getc(fp1);

if(ch==EOF)

break;

else if(ch=='(')

bra1++;

else if(ch==')')

bra2++;

else if(ch==';')

col++;

}

if(flag==0)

printf("\n ERROR: UNDEFINED SYMBOL for ");

else if(bra1!=1)

printf("\n ERROR: BRACKET ERROR '(' ");

else if(bra2!=1)

printf("\n ERROR: BRACKET ERROR ')' ");

else if(col!=2)

printf("\n ERROR: SEMICOLON ERROR ';' ");

else

printf("\n NO ERROR: ");

}

fclose(fp1);

getch();

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

Syntax of for loop in c language?

for(i=0;i&lt;=0;i++)


What is the use of compiler in c language?

Compilers check correctness of your program syntax, memory allocation procedures and so on.


What is odd loop in 'C' program?

odd loop means at least the loop execute once.


Is c an application or software?

"C" is a programming language. It is implemented by writing a program using the C syntax and then translated by a compiler, which is an application program.


Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


For loop program turbo c making a right triangle?

yes


How do you write a c program to design calculator using loop?

Wr


What the syntax of for loop in c?

for (&lt;exp1&gt;; &lt;exp2&gt;; &lt;exp3&gt;) &lt;statement&gt; exp1 and exp3 are optional; statement can be null-statement or block-statement. Correction: All expressions are optional. An infinite loop has no expressions: for(;;);


C program algorithm for simple interest using while loop?

Not used


What are the basic syntax of c program?

You have to be more specific. What part of C syntax? Do you want the syntax for outputing a number or sentence, do you want to syntax for creating a array, struct, a user defined function or what? #include iostream using namespace std; int main { cout &lt;&lt; "Hello World!" &lt;&lt; endl; return 0; };


What is java program made of?

basic unit of C is structure like procedure ,syntax's, error's compiler etc


How do you write a program in c?

Writing a program in C is not a difficult task. You simply need to have a compiler or an editor supporting the syntax defined in the C Standard. An example of the "Hello, World!" program in C: #include &lt;stdio.h&gt; int main () { printf("Hello, World!"); return 0; }