Hello.
for one of my assignment, I need to create any program using the C language and that must contain the following:
- Error Checking
- Use of Functions
- Menu system
- Array Processing
It can be about anything, nothing specified but must contain the features mentioned above
Thank you
//Required c code:
#include <stdio.h>
#include <errno.h>
#include <string.h>
int add(int a, int b){
return a+b;
}
int main ()
{
//error handling
FILE *fp;
// If a file is opened which does not
exist,
// then it will be an error and
corresponding
// errno value will be set
fp = fopen(" abc.txt ", "r");
// opening a file which does
// not exist.
printf("Value of errno: %d\n ", errno);
printf("The error message is : %s\n",
strerror(errno));
perror("Message from perror");
//Use of function
int d = add(1,2);
printf("Sum of 1 & 2 is: %d",d);
//menu system
int x;
printf("\nSelect an item: ");
printf("\n1. Add");
printf("\n2. Subtract");
printf("\n3. Multiply\n");
scanf("%d",&x);
switch (x) {
case 1:
printf("Add selected\n");
break;
case 2:
printf("Subtarct selected\n");
break;
case 3:
printf("Multiply selected\n");
break;
default:
break;
}
//array processing
int arr[3] = {1,2,3};
for(int i = 0;i<3;i++){
printf("%d
",arr[i]*3);
}
return 0;
}
Please refer to the screenshot of the code to understand the indentation of the code
Output:
Hope this helped. Please do upvote and if there are any queries please ask in comments section.
Get Answers For Free
Most questions answered within 1 hours.