In this lab you need to write a program in C that can perform following tasks: User provides name of a c file in command
Posted: Fri May 20, 2022 10:02 am
In this lab you need to write a program in C
that can perform following tasks:
User provides name of a c file in command
line argument.
Program opens the file and reads it line by
line.
Program should display the input c file on
console with line numbers appended against
each
line.
It then searches and identifies macro in the
file. A macro has the structure
#define <MacroHead> «MacroBody>
If a macro line is found in the program, the
head and body of the MACRO is then
displayed on
console as shown in the sample run.
Note that you only need to take care of a
single appearance of macro in the c file.
If there is no macro in the file, the program
should not display any output on console.
/lin.c
#include <stdio.h>
int main)
printf (MSG) :
return O;
Program is executed as follow:
$ gec lab5.c -0 lab5
$/lab5 in.c
since there is no macro defined in the input c
file so nothing is displayed
on console, except the contents of input file
with line
numbering
1. #include <stdio.h>
2.
3,
4. int main()
Sample Run//in.c#include <stdio.h>#define MSG "Good Morning"int main){printf(MSG);return 0;Program is executed as follow:$qcc lab5.c-0 lab5$./lab5 in.cSince there is no macro defined in the inputCfile so nothing is displayedon console,except thecontentsofinput file with line numbering1. #include‹stdio.h>2.3 -int main)5.{6.printf (MSG) ;7.return 0;8. }Sample Run//in.c#include <stdio.h>#define MSG "Good Morning"int main){printf(MSG);return 0;Program is executed as follow:$ gcc lab5.c-0 lab5S./lab5 in.c1. #include <stdio.h>2. #define MSG"Good Morning"3.4. int main)5. {6.printf (MSG) ;7.return 0;8. }MACRO statement found on line number:MACRO is MSGMACRO STRING is"Good Morning"
Sample Run
//in.c
#include <stdio.h>
#define MSG "Good Morning"
int main)
{
printf(MSG);
return 0;
Program is executed as follow:$qcc lab5.c-0 lab5$./lab5 in.cSince there is no macro defined in the inputCfile so nothing is displayedon console,except thecontentsofinput file with line numbering1. #include‹stdio.h>2.3 -int main)5.{6.printf (MSG) ;7.return 0;8. }Sample Run//in.c#include <stdio.h>#define MSG "Good Morning"int main){printf(MSG);return 0;Program is executed as follow:$ gcc lab5.c-0 lab5S./lab5 in.c1. #include <stdio.h>2. #define MSG"Good Morning"3.4. int main)5. {6.printf (MSG) ;7.return 0;8. }MACRO statement found on line number:MACRO is MSGMACRO STRING is"Good Morning"
Program is executed as follow:
$
qcc lab5.c
-0 lab5
$
./lab5 in.c
Since there is no macro defined in the input
C
file so nothing is displayed
on console,
except the
contents
of
input file with line numbering
1. #include
‹stdio.h>
2.
3 -
int main)
5.
{
6.
printf (MSG) ;
7.
return 0;
8. }
Sample Run
//in.c
#include <stdio.h>
#define MSG "Good Morning"
int main)
{
printf(MSG);
return 0;
Program is executed as follow:
$ gcc lab5.c
-0 lab5
S
./lab5 in.c
1. #include <stdio.h>
2. #define MSG
"Good Morning"
3.
4. int main)
5. {
6.
printf (MSG) ;
7.
return 0;
8. }
MACRO statement found on line number:
MACRO is MSG
MACRO STRING is
"Good Morning"
that can perform following tasks:
User provides name of a c file in command
line argument.
Program opens the file and reads it line by
line.
Program should display the input c file on
console with line numbers appended against
each
line.
It then searches and identifies macro in the
file. A macro has the structure
#define <MacroHead> «MacroBody>
If a macro line is found in the program, the
head and body of the MACRO is then
displayed on
console as shown in the sample run.
Note that you only need to take care of a
single appearance of macro in the c file.
If there is no macro in the file, the program
should not display any output on console.
/lin.c
#include <stdio.h>
int main)
printf (MSG) :
return O;
Program is executed as follow:
$ gec lab5.c -0 lab5
$/lab5 in.c
since there is no macro defined in the input c
file so nothing is displayed
on console, except the contents of input file
with line
numbering
1. #include <stdio.h>
2.
3,
4. int main()
Sample Run//in.c#include <stdio.h>#define MSG "Good Morning"int main){printf(MSG);return 0;Program is executed as follow:$qcc lab5.c-0 lab5$./lab5 in.cSince there is no macro defined in the inputCfile so nothing is displayedon console,except thecontentsofinput file with line numbering1. #include‹stdio.h>2.3 -int main)5.{6.printf (MSG) ;7.return 0;8. }Sample Run//in.c#include <stdio.h>#define MSG "Good Morning"int main){printf(MSG);return 0;Program is executed as follow:$ gcc lab5.c-0 lab5S./lab5 in.c1. #include <stdio.h>2. #define MSG"Good Morning"3.4. int main)5. {6.printf (MSG) ;7.return 0;8. }MACRO statement found on line number:MACRO is MSGMACRO STRING is"Good Morning"
Sample Run
//in.c
#include <stdio.h>
#define MSG "Good Morning"
int main)
{
printf(MSG);
return 0;
Program is executed as follow:$qcc lab5.c-0 lab5$./lab5 in.cSince there is no macro defined in the inputCfile so nothing is displayedon console,except thecontentsofinput file with line numbering1. #include‹stdio.h>2.3 -int main)5.{6.printf (MSG) ;7.return 0;8. }Sample Run//in.c#include <stdio.h>#define MSG "Good Morning"int main){printf(MSG);return 0;Program is executed as follow:$ gcc lab5.c-0 lab5S./lab5 in.c1. #include <stdio.h>2. #define MSG"Good Morning"3.4. int main)5. {6.printf (MSG) ;7.return 0;8. }MACRO statement found on line number:MACRO is MSGMACRO STRING is"Good Morning"
Program is executed as follow:
$
qcc lab5.c
-0 lab5
$
./lab5 in.c
Since there is no macro defined in the input
C
file so nothing is displayed
on console,
except the
contents
of
input file with line numbering
1. #include
‹stdio.h>
2.
3 -
int main)
5.
{
6.
printf (MSG) ;
7.
return 0;
8. }
Sample Run
//in.c
#include <stdio.h>
#define MSG "Good Morning"
int main)
{
printf(MSG);
return 0;
Program is executed as follow:
$ gcc lab5.c
-0 lab5
S
./lab5 in.c
1. #include <stdio.h>
2. #define MSG
"Good Morning"
3.
4. int main)
5. {
6.
printf (MSG) ;
7.
return 0;
8. }
MACRO statement found on line number:
MACRO is MSG
MACRO STRING is
"Good Morning"