command-line argument

58 阅读1分钟
  1. Please briefly describe what the run time error is in C language.
  2. Write a program that prints each command-line argument on a new line.
    Example:
    Input in CMD: ./program hello world
    Output:
  3. Write a program that reads a line of text from the user using fgets and prints it 
    back.
    Example:
    Input from the keyboard:
    Output to the screen:
  4. Write a program that reads a line of text using fgets and calculates its length 
    (excluding the newline character).
    Example:
    Input from the keyboard:
    Output to the screen:
  5. Define a structure Rectangle with two members: length and width. Ask the user 
    to input the length and width of a rectangle. Calculate and output the area and 
    perimeter of the rectangle.
    Input: 
    Output:
  6. Define a structure Student with the following members:
    ⚫ name (a string)
    ⚫ roll_number (an integer)
    ⚫ marks (a float)
    Write a program to:
    ⚫ Declare an array of 3 Student structures.
    ⚫ Ask the user to input the details of each student.
    ⚫ Print the name and marks of the student with the highest marks.
    Input: 
    ‘Output: 
    --- Student with Highest Marks ---
    Name: Eva 
    Marks: 90.00
  7. Write a C program that defines a Student structure with fields for name and 
    age. Create an array of students, populate it with sample data, and sort the 
    array by student names in alphabetical order.
    Instructions:
  8. Define a Structure:
    • Create a struct named Student with the following members:
    • char name[50]; to store the student's name.
    • int age; to store the student's age.
  9. Create an Array of Structures:
    • Define an array of Student structures to store information for at 
    least 5 students.
  10. Populate the Array:
    • Initialize the array with sample data for student names and ages.
  11. Sort the Array:
    • Write a function to sort the array by student names in alphabetical 
    order using a suitable sorting algorithm.
  12. Print the Sorted Array:
    • Display the sorted list of students, including their names and age.
    Input: 
    Student 1: 
    Name: Tom
    Age: 32
    Student 2:
    Name: Dick
    Age: 43
    Student 3:
    Name: Jane
    Age: 24
    Output:
    Dick: 43
    Jane: 24
    Tom: 32

WX:codinghelp