Question

Hello. for one of my assignment, I need to create any program using the C language...

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

Homework Answers

Answer #1

//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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How could I create a very basic assembly program that is able to use string literals,...
How could I create a very basic assembly program that is able to use string literals, reserved words, and identifiers? I also need to process some directives, instructions, and labels as well. Could someone generate a simple assembly program to do these things? Thank you! My apologies, x86 processors. It's also a 32-bit program! We are using Visual Studio, and writing 32-bit programs. This program can literally do anything, as long as it meets the following requirements as described above.
I am trying to write a program in C language but keep running into errors. Any...
I am trying to write a program in C language but keep running into errors. Any help would be awesome. here is my code I have so far. #include <stdio.h> #include <conio.h> #include <string.h> int main(){    int lenght, i = 0, state = 0;    char line[100];    printf("enter the string for checking of comment line: \n");    gets(line);    while(i < strline(line)){        switch(state){            case 0: if (line[i] == '/'){               ...
Hello, My name is Cierra and I'm a bit nervous on where I need to start...
Hello, My name is Cierra and I'm a bit nervous on where I need to start to complete my assignment. I would appreciate some tips on what formula's to use and what direction I should take to answer a few questions. I want to have a better understanding of what questions I am getting myself into. Thank you. Cryptography: What does this coded message say?? Matrix inverses can provide a simple and effective procedure for encoding and decoding messages. 40  ...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this assignment must be submitted by the deadline on Blackboard. Submitting your assignment early is recommended, in case problems arise with the submission process. Late submissions will be accepted (but penalized 10pts for each day late) up to one week after the submission deadline. After that, assignments will not be accepted. Assignment The object of this assignment is to construct a mini-banking system that helps...
My assignment is listed below. I already have the code complete, but I cannot figure out...
My assignment is listed below. I already have the code complete, but I cannot figure out how to complete this portion: You must create a makefile to compile and build your program. I can't figure out if I need to create a makefile, and if I do, what commands do I use for that? Create a  ContactInfo class that contains the following member variables: name age phoneNumber The ContactInfo class should have a default constructor that sets name = "", phoneNumber...
For this assignment you need to write a parallel program in C++ using OpenMP for vector...
For this assignment you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is: #pragma...
Assignment Overview This programming exercise introduces generics and interfaces. The students must create methods that accept...
Assignment Overview This programming exercise introduces generics and interfaces. The students must create methods that accept generic parameters and perform operation on them. Deliverables A listing of the fully commented, working source code of the Java program Test data for the code A screen shot of the application in execution Step 1 Create a new project. Name it "Assignment_2_1". Step 2 Build a solution. Write the Java source code necessary to build a solution for the problem below:You have just...
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...