0% found this document useful (0 votes)
69 views7 pages

CSE 332 - 201-15-3452 - Lab-Report 03

This document contains an assignment submission for a Compiler Design Lab course. The assignment asks the student to write C programs that: [1] take multiple lines of input and count the number of lines; [2] take multiple lines of input and identify any comments; [3] take multiple lines of input and remove any single-line or multi-line comments. The student has provided their answers to each question, along with screenshots confirming the programs were run correctly.

Uploaded by

Avishek Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views7 pages

CSE 332 - 201-15-3452 - Lab-Report 03

This document contains an assignment submission for a Compiler Design Lab course. The assignment asks the student to write C programs that: [1] take multiple lines of input and count the number of lines; [2] take multiple lines of input and identify any comments; [3] take multiple lines of input and remove any single-line or multi-line comments. The student has provided their answers to each question, along with screenshots confirming the programs were run correctly.

Uploaded by

Avishek Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Assignment

Course Title: Compiler Design Lab


Course code: CSE 332

Submitted To:
Mr. Mushfiqur Rahman

Senior Lecturer
Department of CSE
Daffodil International University

Submitted By:
Name : Avishek Das
ID : 201-15-3452
Section : PC-F
Department of CSE

Date of Submission : 29-08-22


Question: 01
Write a C program that will take multiple lines as input and count the
number of Lines.

Ans :
#include<stdio.h>

#include<string.h>

int main()

char str[50];

scanf("%[^ #]",str);

int i,line=0;

for(i=0;str[i]!='\0';i++)

if(str[i]=='\n')

line++;

printf("Number of total lines: %d\n",line);

return 0;

Screenshot
Question: 02
Write a C program that will take multiple lines as input and identify the
comments if there any.

Ans :
#include <stdio.h>

#include <string.h>

int main() {

char str[100];

int Q;

scanf("%[^#]", str);

int i, j, k = 1, k1 = 1, L, line = 0, m = 0;

for (i = 0; str[i] != '\0'; i++) {

if (str[i] == '/' && str[i + 1] == '/') {

printf("Single Comment-%d: ", k);

for (j = i; str[j] != '\n'; j++)

printf("%c", str[j]);

printf("\n");

k++;

} else if (str[i] == '/' && str[i + 1] == '*') {

printf("Multiple-line comment-%d: ", k1);

for (L = i; str[L] != '\0'; L++) {

if (str[L] == '*' && str[L + 1] == '/') {

m = 1;

break;
}

printf("%c", str[L]);

if (m == 1)

break;

printf("\n");

k1++;

return 0;

Screenshot
Question: 03
Write a C program that will take multiple lines as input and remove the
single line/multiple line comments if there any.

Ans :
#include<stdio.h>

#include<string.h>

#include<conio.h>

void clrscr()

system("@cls||clear");

int main() {

clrscr();

char str[128];

//printf("Enter a multi line string( press ';' to end input)\n");

scanf("%[^;]s", str);

//printf("Input String = %s", str);

int l=strlen(str),j=0;

char tmp[128];

for(int i=0;i<l;i++){
if(str[i]=='/' && str[i+1]=='/'){

for(;i<l-1;i++){

if(str[i]==10){

break;

else if(str[i]=='/' && str[i+1]=='*'){

for(;i<l;i++){

if(str[i]=='*' && str[i+1]=='/'){

i++;

break;

else {

//printf("%d %c \n",i,str[i]);

tmp[j]=str[i];

j++;

}
int len=strlen(tmp);

for(int i=0;i<len;i++){

printf("%c",tmp[i]);

}printf("\n");

return 0;

Screenshot

You might also like