Debugging Syntax Error Problems
In this section, each of the programs shown below contain syntax errors. Although the programs are small and it is likely that you will find the errors quickly (possibly without compiling the code) it is to your benefit to see what error messages are produced should you make such an error as shown.
For each program below:
1) compile the program WITH the syntax error in place (copy and paste), write down the error message your compiler gives you. The reason to do this is because you need to learn what the error messages are saying to you. Writing it down will help you remember.
2) explain in your own words what the problem is.
3) Fix the error, recompile and match against the output provided. explain how you did it.
Problem 1
#include <stdio.h>
Int main(void){
printf("oh bug where are you?\n");
return 0;
}
What your program will show if it was running properly:
oh bug where are you?
What error message did you get when you compiled it?
What was wrong and how did you fix the above program?
Problem 2
#include <stdio.h>
int main(void){
printf("This is a \"buggy" program\n");
return 0;
}
What your program will show if it was running properly:
This is a "buggy" program
What error message did you get when you compiled it?
What was wrong and how did you fix the above program?
Problem 3
#include <stdio.h>
int main(void){
int first;
int second;
printf("Please enter a number: ");
scanf("%d",&first);
printf("Please enter another number: ");
scanf("%d",&Second);
printf("%d + %d = %d \n",first,second, frist+second);
}
What error message did you get when you compiled it?
What was wrong and how did you fix the above program?