56% found this document useful (9 votes)
7K views

Type Checking C Program

The document describes a type checking C program that takes user input for variables a and b, determines if they are of type "int" by calling the type() function, and checks for a type error if their types do not both equal "int". The program prompts the user to enter values for variables a and b, calls type() to get the type of each in a message string, prints the types, and checks for a type match or error.

Uploaded by

sendhil28
Copyright
© © All Rights Reserved
56% found this document useful (9 votes)
7K views

Type Checking C Program

The document describes a type checking C program that takes user input for variables a and b, determines if they are of type "int" by calling the type() function, and checks for a type error if their types do not both equal "int". The program prompts the user to enter values for variables a and b, calls type() to get the type of each in a message string, prints the types, and checks for a type match or error.

Uploaded by

sendhil28
Copyright
© © All Rights Reserved
You are on page 1/ 4

CS6612 COMPILER LAB

JP COLLEGE OF ENGINEERING

Type Checking Program


#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
char* type(char[],int);
void main()
{
char a[10],b[10],mess[20],mess1[20];
int i,l;
clrscr();
printf( "\n\n int a,b;\n\n int c=a+b\n");
printf( "\n\n Enter a value for a\n");
scanf("%s", a);
l=strlen(a);
printf(" \n a is :");
strcpy(mess,type(a,l));
printf("%s",mess);

N.SENTHIL MURUGAN AP/CSE

[email protected]

CS6612 COMPILER LAB

JP COLLEGE OF ENGINEERING

printf( "\n\n Enter a value for b\n\n");


scanf("%s",b);
l=strlen(b);
printf(" \n b is :");
strcpy(mess1,type(b,l));
printf("%s",mess1);
if(strcmp(mess,"int")==0&&strcmp(mess1,"int")==0)
{
printf("\n\n No Type Error");
}
else
{
printf("\n\n Type Error");
}
getch();
}
char* type(char x[],int m)
{
int i;
char mes[20];
N.SENTHIL MURUGAN AP/CSE

[email protected]

CS6612 COMPILER LAB

JP COLLEGE OF ENGINEERING

Output :

N.SENTHIL MURUGAN AP/CSE

[email protected]

CS6612 COMPILER LAB

N.SENTHIL MURUGAN AP/CSE

JP COLLEGE OF ENGINEERING

[email protected]

You might also like