我曾被派到大学进行奇怪的项目。 要求我从特定投入C方案中提取可变的定义和参考资料。
投入方案中的每一行都包含各自在开始时的线数,然后是空间,然后是实际代码。
Consider the following program..
1 int main()
2 {
3 int a,b,c;
4 printf("Enter the values of a and b
");
5 scanf("%d%d",&a,&b);
6 c=a+b;
7 printf("The sum of two numbers is %d",c);
8 }
And the input for the program which I m developing is a C program, in which single line consists of a single statement.. ie, we know that a whole program can be written in a single line. But not in my case, that is once there is a termination(semicolon), the lines following the semi colon is shifted to next line..
我工作的任何途径都是在投入C方案中摘录各种定义/声明以及可变的使用/参考。
Consider the above program, In line number 3, variables a,b and c are declared, hence it has to be printed under the "definition" column of the output..
同样,在表5中,a和b的数值正用扫描仪表加以初步计算,因此,a和b的变量应在产出的定义栏下印刷。
Now consider the statement 6, The value of variable c is being initialized/defined hence c must be printed under the definition column.. At the same time, values of a and b are being used to determine the value of c, hence variables a and b must be printed under the "reference" column of the output..
最后,表7提到/使用了变数c的价值,因此,变数c必须在参考栏下印刷。
The sample output of the program is as shown below..
Line Number Defined Variable Referenced Variable
_____________________________________________________________________
1 -- --
2 -- --
3 a,b,c --
4 -- --
5 a,b --
6 c a,b
7 -- c
8 -- --
Can anyone tell me how to solve the problem???? Remember, I need to write a C/C++ program or even shell script is allowed for the project.. I need to consider the mathematical expressions, logical expressions, built in function calls, user defined function calls and function definitions as well..
Thanks in advance..