answersLogoWhite

0

C program to check a for loop syntax?

Updated: 12/20/2022
User Avatar

Wiki User

11y ago

Best Answer

//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

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program to check a for loop syntax?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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'


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

Wr


For loop program turbo c making a right triangle?

yes


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 for in c plus plus?

for is a loop in C++. It is used to repeat some instructions for required time. Syntax : for(counter initialization;condition;counter update) e.g. //Program to print numbers from 1-100 #include&lt;iostream.h&gt; #include&lt;conio.h&gt; void main() { int i; for(i=1;i&lt;=100;i++) cout&lt;&lt;i&lt;&lt;endl; getch(); }


What is java program made of?

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