Command Line Arguments-Network Programming-Assignment, Exercises of Network Programming

This assignment is for Network Programming course. Its about Command Line Arguments. It was given by Prof. Tausiq Dasgupta at Babasaheb Bhimrao Ambedkar University. It includes: Networking, Programming, Command, Argument, Function, Socket, Casting, Parameter, Integer, Accuracy

Typology: Exercises

2011/2012

Uploaded on 07/31/2012

dhanush
dhanush 🇮🇳

4

(3)

36 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Network Programming
Assignment # 1
November 4, 2009
docsity.com
pf3

Partial preview of the text

Download Command Line Arguments-Network Programming-Assignment and more Exercises Network Programming in PDF only on Docsity!

Network Programming

Assignment # 1

November 4 , 2009

Question: Define the following:

**1. Command line arguments

  1. Type casting
  2. Socket** a. Function definition (signature) b. Return type c. Arguments

1. Command Line Arguments:

C provides a fairly simple mechanism for retrieving command line parameters entered by the user. It passes an argv parameter to the main function in the program.

Example:

int main(int argc, char *argv[])

In this code, the main program accepts two parameters, argv and argc. The argv parameter is an array of pointers to string that contains the parameters entered when the program was invoked at the UNIX command line. The argc integer contains a count of the number of parameters.

The *char argv[] line is an array of pointers to string. In other words, each element of the array is a pointer, and each pointer points to a string (technically, to the first character of the string). Thus, argv[0] points to a string that contains the first parameter on the command line (the program's name), argv[1] points to the next parameter, and so on. The argc variable tells you how many of the pointers in the array are valid.

2. Type Casting:

Type Cating refers to changing an entity of one data type into another. This is done to take advantage of certain features of type hierarchies. For instance, values from a more limited set, such as integers, can be stored in a more compact format and later converted to a different format enabling operations not previously possible, such as division with several decimal places' worth of accuracy.

Example:

main() { float a;