This is the question and I can't understand any bit of it. Can someone suggest any logic or method to do? Sorry for not being clear with the question earlier.
Write a program to display lines that contain hard-coded constants in a given C-code file ( C file name is passed a command-line argument).In addition, it also displays the line number on which hard-coding is detected. You can assume that the code is given to your program goes through compilation without errors. The following cases of hard-coding can be treated as normal and need not be reported by the program. • Assignments to 0 • Assignments to 1 • Increments and decrements in steps of 1 For example, given the following code:
#define MULT(A,B)A*B
#define N 5
main()
{
int i=0;
int a;
printf("%d\n", MULT(1+2, 3));
printf("%d\n", MULT(1+2, 3+4));
i=i+5;
for(i=0;i<N;i=i+1)
printf("i",i);
i=1;
while(i<5)
printf("i",i++);
a=0xdeadbeef;
i=5;
}
For the above code the output should be:
9: printf("%d\n", MULT(1+2, 3));
10: printf("%d\n", MULT(1+2, 3+4));
12: i=i+5;
17. while(i<5)
19. a=0xdeadbeef;
21. i=5;
The program should not report following lines as hard-coded:
for(i=0;i<N;i=i+l) /* Assignment to 0, increments in steps of 1 */
int i=0;/* Asslgnment to 0 */
i=1;/* Assignment to 1 */
/Image is also provided in this post./
User contributions licensed under CC BY-SA 3.0