Unit 5 54
Unit 5 54
Output:
/* Data in data.txt
10 11 12 13 14 15. */
The average of the numbers is 12.5
Output
The output is as follows −
0 (always).
Explore our latest online courses and learn new skills at your
own pace. Enroll and become a certified expert to boost your
career.
fseek ( )
It is to make the file pntr point to a particular location in a file.
The syntax is as follows −
fseek(file pointer, offset, position);
Offset
The no of positions to be moved while reading or
writing.
If can be either negative (or) positive.
o Positive - forward direction.
Position
It can have three values, which are as follows −
0 – Beginning of the file.
1 – Current position.
2 – End of the file.
Example
fseek (fp,0,2) - fp moved 0 bytes forward from the end of
the file.
fseek (fp, 0, 0) – fp moved 0 bytes forward from
beginning of the file
fseek (fp, m, 0) – fp moved m bytes forward from the
beginning of the file.
fseek (fp, -m, 2) – fp moved m bytes backward from the
end of the file.
Errors
The errors related to fseek () function are as follows −
fseek (fp, -m, 0);
fseek(fp, +m, 2);
Output
You have entered 4 arguments:
./main
geeks
for
geeks
if (argc == 1)
printf("\nNo Extra Command Line
Argument Passed "
"Other Than Program
Name");
if (argc >= 2) {
printf("\nNumber Of Arguments
Passed: %d", argc);
printf("\n----Following Are The
Command Line "
"Arguments Passed----");
for (int i = 0; i < argc; i++)
printf("\nargv[%d]: %s", i,
argv[i]);
}
return 0;
}
Output in different scenarios:
Output
Program Name Is: ./a.out
No Extra Command Line Argument Passed
Other Than Program Name
2. Three arguments: When the above code is compiled and
executed with three arguments, it produces the following
output.
Terminal Input
$ ./a.out First Second Third
Output
Program Name Is: ./a.out
Number Of Arguments Passed: 4
----Following Are The Command Line
Arguments Passed----
argv[0]: ./a.out
argv[1]: First
argv[2]: Second
argv[3]: Third
3. Single Argument: When the above code is compiled and
executed with a single argument separated by space but inside
double quotes, it produces the following output.
Terminal Input
$ ./a.out "First Second Third"
Output
Program Name Is: ./a.out
Number Of Arguments Passed: 2
----Following Are The Command Line
Arguments Passed----
argv[0]: ./a.out
argv[1]: First Second Third
4. A single argument in quotes separated by space: When
the above code is compiled and executed with a single
argument separated by space but inside single quotes, it
produces the following output.
Terminal Input
$ ./a.out 'First Second Third'
Output
Program Name Is: ./a.out
Number Of Arguments Passed: 2
----Following Are The Command Line
Arguments Passed----
argv[0]: ./a.out
argv[1]: First Second Third