The document discusses various C programming concepts related to structures, unions, files and storage classes. It defines structures and unions, and describes how to declare structure variables, initialize structures, define arrays of structures and use pointers to structures. It also covers nested structures, self-referential structures, and passing structures to functions. The document briefly explains storage classes like auto, static, extern and register. It also discusses files and streams in C programming.
Structures in Functions | Pointers to structures | Accessing structure members | Using pointer as a function argument | Array of structures | Self referential structures
Structures-Declaring and Initializing, Nested structure, Array of Structure, Passing Structures to functions, Unions, typedef, enum, Bit fields.
Pointers: Declarations, Pointer arithmetic, Pointers and functions, call by value, Call by reference, Pointers and Arrays, Arrays of Pointers, Pointers and Structures. Meaning of static and dynamic memory allocation, Memory allocation functions.
Files: File modes, File functions, and File operations, Text and Binary files, Command Line arguments Preprocessor directives. Macros: Definition, types of Macros, Creating and implementing user defined header files
Structures in Functions | Pointers to structures | Accessing structure members | Using pointer as a function argument | Array of structures | Self referential structures
Structures-Declaring and Initializing, Nested structure, Array of Structure, Passing Structures to functions, Unions, typedef, enum, Bit fields.
Pointers: Declarations, Pointer arithmetic, Pointers and functions, call by value, Call by reference, Pointers and Arrays, Arrays of Pointers, Pointers and Structures. Meaning of static and dynamic memory allocation, Memory allocation functions.
Files: File modes, File functions, and File operations, Text and Binary files, Command Line arguments Preprocessor directives. Macros: Definition, types of Macros, Creating and implementing user defined header files
A structure is a collection of variables referenced under one name providing a convenient means of keeping related information together. The structure definition creates a format that may be used to declare structure variables in a program later. data structure in c questions and answer
CS 23001 Computer Science II Data Structures & AbstractionPro.docxfaithxdunce63732
CS 23001 Computer Science II: Data Structures & Abstraction
Project #4
Spring 2015
Objectives:
· Develop and use a Tree ADT (n-ary)
· Apply and use tree traversal algorithms
· Manipulate trees by inserting and deleting nodes
· Apply and use STL
Problem:
Build a program profiler. Construct a program to instrument C++ source code to support program profiling.
It is often important to determine how many times a function or statement is executed. This is useful not only for debugging but for determining what parts of a program may need to be optimized. This process is called profiling. That is, a execution profile presents how many times each part of a program is executed using a given set of input data (or for some run time scenario). To compute a profile, statements need to be added to the code that keep track of how many times a function or statement is executed. The process of adding these statements is called instrumenting the code.
To implement a profiler one must first parse the source code and generate an Abstract Syntax Tree (AST) of the code. Each node of the AST describes the syntactic category of the code stored within it (function, statement, while-statement, etc.). So at the top level is a syntactic category corresponding to a program, class, or function (such as in the case of a main). Under that are sub-trees that further detail the syntactic categories of each part of the code. Such things as declarations, parameter lists, while-statement, and expression statements will describe the various parts of the program.
After the AST is generated it can then be traversed and the appropriate syntactic structures can be found that need to be instrumented. Once a construct is found, say a function, new code can be inserted that keeps track of how many times that function is executed.
The most difficult part of constructing a profiler is correctly parsing the source code. Unfortunately, C++ is notoriously difficult to parse. So here we will use a parsing tool called src2srcml. This tool reads in C++ code and marks up the code with XML tags (e.g., block, if, while, condition, name, etc). That is, the output is an AST in XML. The XML representation is called srcML (source code markup language).
A number of srcML data files are provided for the project. However, you can use your own program as input. To run srcML on wasp or hornet you will first need to set a PATH variable so the command can be found. You need to execute the command:
export PATH=/local/opt/srcml/bin:$PATH
It is best if you insert this line into your .bash_profile file in your home directory on wasp/hornet.
Then to generate the srcML file for your own code use the following:
src2srcml main.cpp -o main.cpp.xml
Use the following for a list of all options:
src2srcml --help
More information about srcML can be found at www.srcML.org including a list of all the tag names (see Getting Started). You can also download srcML if you want it on your own machine.
Your .
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
USER DEFINED DATATYPES
STRUCTURE
UNION
TYPEDEF
DIFFERENCE BETWEEN STRUCTURE AND UNION
ENUMERATION (ENUM)
QUIZ SET 4
A structure is a collection of variables referenced under one name providing a convenient means of keeping related information together. The structure definition creates a format that may be used to declare structure variables in a program later. data structure in c questions and answer
CS 23001 Computer Science II Data Structures & AbstractionPro.docxfaithxdunce63732
CS 23001 Computer Science II: Data Structures & Abstraction
Project #4
Spring 2015
Objectives:
· Develop and use a Tree ADT (n-ary)
· Apply and use tree traversal algorithms
· Manipulate trees by inserting and deleting nodes
· Apply and use STL
Problem:
Build a program profiler. Construct a program to instrument C++ source code to support program profiling.
It is often important to determine how many times a function or statement is executed. This is useful not only for debugging but for determining what parts of a program may need to be optimized. This process is called profiling. That is, a execution profile presents how many times each part of a program is executed using a given set of input data (or for some run time scenario). To compute a profile, statements need to be added to the code that keep track of how many times a function or statement is executed. The process of adding these statements is called instrumenting the code.
To implement a profiler one must first parse the source code and generate an Abstract Syntax Tree (AST) of the code. Each node of the AST describes the syntactic category of the code stored within it (function, statement, while-statement, etc.). So at the top level is a syntactic category corresponding to a program, class, or function (such as in the case of a main). Under that are sub-trees that further detail the syntactic categories of each part of the code. Such things as declarations, parameter lists, while-statement, and expression statements will describe the various parts of the program.
After the AST is generated it can then be traversed and the appropriate syntactic structures can be found that need to be instrumented. Once a construct is found, say a function, new code can be inserted that keeps track of how many times that function is executed.
The most difficult part of constructing a profiler is correctly parsing the source code. Unfortunately, C++ is notoriously difficult to parse. So here we will use a parsing tool called src2srcml. This tool reads in C++ code and marks up the code with XML tags (e.g., block, if, while, condition, name, etc). That is, the output is an AST in XML. The XML representation is called srcML (source code markup language).
A number of srcML data files are provided for the project. However, you can use your own program as input. To run srcML on wasp or hornet you will first need to set a PATH variable so the command can be found. You need to execute the command:
export PATH=/local/opt/srcml/bin:$PATH
It is best if you insert this line into your .bash_profile file in your home directory on wasp/hornet.
Then to generate the srcML file for your own code use the following:
src2srcml main.cpp -o main.cpp.xml
Use the following for a list of all options:
src2srcml --help
More information about srcML can be found at www.srcML.org including a list of all the tag names (see Getting Started). You can also download srcML if you want it on your own machine.
Your .
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
USER DEFINED DATATYPES
STRUCTURE
UNION
TYPEDEF
DIFFERENCE BETWEEN STRUCTURE AND UNION
ENUMERATION (ENUM)
QUIZ SET 4
HEAP SORT ILLUSTRATED WITH HEAPIFY, BUILD HEAP FOR DYNAMIC ARRAYS.
Heap sort is a comparison-based sorting technique based on Binary Heap data structure. It is similar to the selection sort where we first find the minimum element and place the minimum element at the beginning. Repeat the same process for the remaining elements.
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
Advancements in technology unveil a myriad of electrical and electronic breakthroughs geared towards efficiently harnessing limited resources to meet human energy demands. The optimization of hybrid solar PV panels and pumped hydro energy supply systems plays a pivotal role in utilizing natural resources effectively. This initiative not only benefits humanity but also fosters environmental sustainability. The study investigated the design optimization of these hybrid systems, focusing on understanding solar radiation patterns, identifying geographical influences on solar radiation, formulating a mathematical model for system optimization, and determining the optimal configuration of PV panels and pumped hydro storage. Through a comparative analysis approach and eight weeks of data collection, the study addressed key research questions related to solar radiation patterns and optimal system design. The findings highlighted regions with heightened solar radiation levels, showcasing substantial potential for power generation and emphasizing the system's efficiency. Optimizing system design significantly boosted power generation, promoted renewable energy utilization, and enhanced energy storage capacity. The study underscored the benefits of optimizing hybrid solar PV panels and pumped hydro energy supply systems for sustainable energy usage. Optimizing the design of solar PV panels and pumped hydro energy supply systems as examined across diverse climatic conditions in a developing country, not only enhances power generation but also improves the integration of renewable energy sources and boosts energy storage capacities, particularly beneficial for less economically prosperous regions. Additionally, the study provides valuable insights for advancing energy research in economically viable areas. Recommendations included conducting site-specific assessments, utilizing advanced modeling tools, implementing regular maintenance protocols, and enhancing communication among system components.
About
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Technical Specifications
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
Key Features
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface
• Compatible with MAFI CCR system
• Copatiable with IDM8000 CCR
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
Application
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
We have compiled the most important slides from each speaker's presentation. This year’s compilation, available for free, captures the key insights and contributions shared during the DfMAy 2024 conference.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Overview of the fundamental roles in Hydropower generation and the components involved in wider Electrical Engineering.
This paper presents the design and construction of hydroelectric dams from the hydrologist’s survey of the valley before construction, all aspects and involved disciplines, fluid dynamics, structural engineering, generation and mains frequency regulation to the very transmission of power through the network in the United Kingdom.
Author: Robbie Edward Sayers
Collaborators and co editors: Charlie Sims and Connor Healey.
(C) 2024 Robbie E. Sayers
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
2. Structures –Pointers to Structures – Array
of Structures – Structures within a Structure –
Functions and Structures – typedef and
Structures – Unions–Practical Applications of
Unions – Enumerations – Bit fields – Storage
Classes –C Preprocessor –Files: Streams – File
type – File operations – Command line
arguments.
4. STRUCTURES
Definition:
Structure having collection of dissimilar data
items that are stored under a single common
name.
The structure is a convenient way for handling
different type of logically related data type
variables.
Example:
student :register number , name , CGPA..etc
employee : employee id , name age ….etc
ice-cream : flavor , price , brand name …etc
5. There are three part of structure
1. Defining a structure
2. Declaring structure variable
3. Accessing object of structure type
7. Description:
struct - it is a keyword
structure element - it is individual variable
declaration, it may be
pointer , normal variable ,
arrays…
; - it is a symbol , A structure must be
ended with semicolon ;
8. Example: keyword
struct book
{
char book_name[];
int pages; structure element
float price;
};
struct book b; structure variable
structure name
Accessing structure element:
b.book_name;
b.pages;
b.price;
10. Declaring a structure variable
A structure variable declaration is similar to
the declaration of normal variable .it having
following statement .
1. Struct keyword
2. Structure name
3. List of structure variable name
4. Terminating with semicolon.
Syntax:
struct structure name var1 , var2…var n ;
12. Rules for declaring a structure
1. A structure must be ended with semicolon .
2. Usually a structure appears at the top of the
source program.
3. The structure element must be accessed with
structure variable with dot operator.
13. Initialization of structure
A structure can be initialized same as other
data types initialization.
Here we assign some values to the
structure elements.
The structure element initialized into two ways:
1. Run time initialization
2. Compile time initialization
17. Array of structure
‘C’ language permits to declare an array of structure
variable.
Example:
If you want to handle more records with in one
structure , we need not specify the number of structure
variable, simply use array of structure variable.
Example:
struct book
{
char name;
int pages;
float price;
};
struct book b[3];
B[0].name
B[0].pages
B[0].price
B[1].name
B[1].pages
B[1].price
B[2].name
B[2].pages
B[2].price
19. Pointer to structure
Here we declare the structure variable as a pointer
then it points all the elements with in the same structure.
Here we add * (asterisk) symbol before the structure
pointer variable.
Syntax:
struct structure name
{
element 1;
element 2;
…….
…….
element n ;
};
struct structure name * pointer variable ;
22. struct book b={“cp” , 150 , 120.75};
struct book *p;
p = &b;
clrscr();
printf(“%s %d %f”, b.name , b.pages , b.price);
printf(“%s %d %f”, p --> name , p -->pages ,
p--> price);
getch();
}
o/p:
cp 150 120.75
cp 150 120.75
23. Structure with function
The main advantage of the C language we
use the function with in the structure.
There are following ways available to pass
the structure variables to the function there
are.
(1) Pass each member value of the structure
as an actual argument of the function.
(2) pass the address location of the structure
to the called function.
(3) Pass a copy of the entire structure to the
called function.
24. 1. Pass each member of the structure as
an actual argument of the function:
Here we pass the entire structure element
value passed from function call to function
definition
So here all the structure values accessed
by the called function( in function definition)
25. 1 - Call by value: Example:
#include<stdio.h>
#include<conio.h>
void main()
{
void show(int , int ); //function declaration
struct student
{
int marks;
int age;
};
struct student s={97, 18};
show(s.marks , s.age); // function call
}
void show(int a , int b) // function definition
{
printf(“%d%d”, a, b);
getch();
}
26. (2) Pass the address location of the structure to
the called function.
Here we pass the entire structure is
passed to another function by address ,
it means the address of the structure is
passed to the called function(function
definition)
27. 2& 3 rd type - Call by reference:
#include<stdio.h>
#include<conio.h>
void main()
{
void show(struct book *); //function declaration
struct book
{
char name[20];
int pages;
float price;
};
struct book b={“cp” , 150 , 255.50};
show(&b); //function call
}
void show(struct book *p) function definition
{
printf(“%s%d%f”, p--> name , p--> pages , p--> price );
getch();
}
28. Nested structure (or) structure with in
a structure
A structure having inside another structure
then that is called as nested structure.
Here we declare the one structure variable
as a member element of another structure , it
is mostly used in complex data structure.
The element of nested structure are
accessed by using dot operator ,
29. Syntax:
struct structure name 1
{
member element 1;
member element 2;
………………………..
member element N ;
};
Struct structure name 2
{
member element 1 …….. N ;
struct structure name 1 variable;
};
struct structure name 2 variable2 ;
30. Self-referential structure
A structure consist of at least a pointer member
pointing to the same structure is known as self
referential structure.
self referential structure is mostly used in linked
data structures , Such as list and trees.
Syntax:
struct book
{
member element 1;
member element 2 ;
……………….
struct book *b1;
};
31. Example:
#include<stdio.h>
Void main()
{
struct book;
{
char bookname[20];
int pages ;
float price;
struct book *b1;
};
struct book b2={“pc” , 350 , 500.00};
b1=&b2;
printf(“%s%d%f” , b1 - - > book name ,
b1 - - > pages ,
b1 - - > price );
}
32. Union
Union holds collection of dissimilar data
items that are stored under a single common
name.
union and structure differs only in the
terms of storage.
In structure memory will be allocated for
all the elements with in the structure.
In union memory allocated for the first
element with in the union , all the other
elements share the common memory space.
35. Storage Classes
1. auto
2. static
3. extern
4. register
Syntax:
storage class type data type variable name;
36. The auto storage class
Automatic variables are also called as auto
variables, which are defined inside a function.
Auto variables are stored in main memory.
Variables has automatic (local) lifetime.
It is a default storage class if the variable is
declared inside the block.
Here initial value is garbage value.
38. 2. The register storage class
Register variables can be accessed faster than
others
Variables are stored in CPU.
It is also declared with in the program.
Variables have automatic (local) lifetime.
Register variables are used for loop counter to
improve the performance of a program.
40. 3. The static storage class
Static variables have static (global) lifetime.
Static variables are stored in the main
memory.
Static variables can be declared in local scope
as well as in the global scope.
Here Last change made in the value of static
variable, remains throughout the program
execution.
42. 4. The extern storage class
Variables that are used by all functions are
called external or global variables.
External variables are stored in main memory.
External variables have static (global) lifetime.
It is declared outside of the function
44. Preprocessor directives
These are placed before the main function in
source program.
If there is any preprocessor directives ,
The appropriate actions are taken and then the
source program is moved to compilation.
preprocessor directives is begin with “#” symbol.
It having two major types conditional and
unconditional.
Types:1.File inclusion
2.Macro substitution
3.Miscellaneous
4.Conditional inclusion
45.
46. File inclusion:
File inclusion is the process of include an
external file. which contains functions or some
other macro definition.
#include <stdio. h> it means to get
stdio.header file from System Libraries
#include "myheader.h“ tells to get
myheader.h from the local directory
Syntax:
#include<filename>
Example:
#include<stdio.h>
#include<add.c>
47. Macro substitution:
It is used to define a macro and use it into
source program, it may be string or integer.
Syntax:
#define identifier string/integer
Example:
#define Pi 3.14
#define name “ragul”
It having three Type:
1. Simple macro - It is used to define some
constants.
2. Augmented macro
3. Nested macro
48. Argumented macro
It is used to define some complex forms in
the source program.
Syntax:
#define identifier(v1 ,v2 ,v3 …. Vn)
string/integer
Example:
#define cube(n) (n*n*n)
#define a,b 10
49. Example for argumented macro:
#include<stdio.h>
#define cube(n) (n*n*n)
void main()
{
int a=3 , b;
b=cube(a);
printf(“The cube of 3 is %d”, b );
}
o/p: The cube of 3 is 27
51. Nested macro:
The macro defined within another macro
called nested macros.
Example:
#define A 5
#define B A+5
52. Conditional inclusion:
#ifdef - used to test the macro, if the macro
is defined or not
#else - used to specify alternative in ifdef
#undef - used to undefined a macro
#endif - the conditional macro must be
terminated from if condition.
53. Example:
# include<stdio.h> file inclusion
#include<conio.h>
#define A 5 simple macro
#ifdef A
#define c 10
#else conditional inclusion
#define c 20
#endif
void main()
{
int r;
r=c*3;
printf(“The value of r is %d”, r);
getch();
}
o/p The value of r is 30
54. Miscellaneous directives
#pragma startup and #pragma exit:
These directives allow us to specify which functions is called first
(program startup) with in multiple functions or specifies which function
program exit . Their usage is as follows:
Example:
void fun1( ) ;
void fun2( ) ;
#pragma startup fun1
#pragma exit fun2
void main( )
{
printf ( “inside main" ) ;
}
void fun1( )
{
printf ( "Inside fun1" ) ;
}
void fun2( )
{
printf ( "Inside fun2" ) ;
}
55. Predefined Macros
1. __DATE__ : It containing the current date
2. __FILE__ : it containing the file name
3. __LINE__ : it representing the current line
number
4. __TIME__ : String containing the current
date.
56. • A file is a collection of related information These
information may be numeric, alphabetic or
alphanumeric.
• ‘C’ Allows data to be stored permanently in a
data file with the help of set of library function
for handling these data files.
• By using these library function to store data in a
secondary devices in the form of data file.
• Operations such as create, open, read, write and
close are performed on files.
File
57. 1. Sequential access
This type of file is to be accessed sequentially ,
Here we want to access the last record in a file you
must read all the records sequentially . It takes more
time for accessing the record.
2. Random access
This type of file allows access to the specific
data directly with out accessing its preceding data
items.
Here the data can be accessed and modified
randomly.
Types of file accessing
58. Here we read and write also manipulate
the character type of data, by using several
standard predefined library function.
Basic file Operations
– Opening a file
– Reading a file
– Writing a file
– Closing a file
Sequential access file (Text file
processing )
59. • fopen()-create a new file or opens an existing
file
• fclose()-close a already opened text file
• fprintf()-writes a set of data values to a file
• fscanf()-reads a set of data values to a file
• fgetc()-read a character from a file
• fputc() -writes a character to a file
Sequential access functions
60. fopen()
Create a new file or opens an existing file.
Opening a file means creating a new file with
specified filename with accessing mode.
Syntax:
FILE *file_pointer _name ; //
file_pointer_name = fopen(“filename.txt ” , mode”);
Example:
FILE *a ;
a = fopen( “emplyeeinfo.txt”, “w”);
61. fclose()
It close a already opened text file
A file must be closed after all the
operation have been completed
Syntax:
fclose(file_pointer_name);
Example:
FILE *a ;
a = fopen( “emplyeeinfo.txt”, “r”);
fclose(a);
62. File read:
Read the character from the file using fgetc()
The fgetc() function is used to read a character
from the file which is opened in read mode.
Syntax:
c= fgetc(file pointer name );
Reading data from the file :fscanf()
Reads a set of data values to a file ,
It is similar to the scanf () except that fscanf() to
read the data from secondary storage disk.
Syntax:
fscanf ( fptr , “format/control string ” , &v1,&v2..&vn );
Example:
fscanf( fptr , “ %d%s %d”, &rollno , &sname ,&tot);
63. File write :
Write a character to a file : fputc()
This function is used to write a character variable
into a file that is opened in write mode.
Syntax:
fputc( x , fptr1);
Write data to a file :fprintf()
This function writes a set of data values to a file , it
is similar to printf() except that fprintf() function write
data into the disk.
Syntax:
fprintf(fptr , “format/control string ” , v1,v2..);
Example:
fprintf( fptr , “%d %s %d ”, rollno,sname,total);
64. File mode Description
r Open a text file for reading.
w Create a text file for writing, if it exists, it is
overwritten.
a Open a text file and append text to the end of the
file.
r+ existing file opened for both reading and writing
w+ new file is opened for reading and writing
a+ existing file opened for both reading and writing
File Accessing modes
65. rb Open a binary file for reading.
wb Create a binary file for writing, if it
exists, it is overwritten.
ab existing binary file opened for both
reading and writing
BINARY FILE
66. Example program: to create a file to store details of
n students.
#include<stdio.h>
#include<conio.h>
Void main()
{
int rollno , totalmark , i , n;
char name[20];
FILE *fptr;
fptr = fopen( “student.txt” , “w”);
clrscr();
printf(“enter the how many students”);
scanf( “%d” , &n);
68. 1. fseek()-sets the position to desired point in
the file
2. rewind()-sets the position to the beginning
of the file
3. ftell()-gives the current position in the file
4. fgetpos()
5. fsetpos()
Random access files
69. 1. F seek()-this function is used to set the file position
pointer to the given text file .
Syntax:
int fseek(FILE *stream , long offset , int origin);
Description:
FILE * stream_pointer - file pointer name
Offset - is an integer value that gives the number of
bytes to move forward or backward.
Origin argument may have values
– SEEK_SET - Beginning of file
– SEEK_CUR - Current position of the file pointer
– SEEK_END - End of file
Example:
Int fseek( fptr, 0L , SEEK_SET)
70. 2. ftell()
This function is used to know the current position of the file
pointer , it is used to read or write the data from the current
position.
Syntax:
ftell (FILE *stream);
Example:
printf(“%d” , ftell(fptr));
3. rewind()
sets the position to the beginning of the file.
After this process the file pointer is moved into beginning of
the file .
Syntax:
void rewind( FILE *fptr);
Example:
void rewind( fptr );
71. The rewind() function is equivalent to
calling fseek() with the following parameter.
fseek( file pointer name , 0L , SEEK_SET);
Example :
FILE *fptr;
fptr= fopen( “student.txt” , “r”);
fseek( fptr , 0L , SEEK_SET);
72. 4. fgetpos()
The fgetpos() function is used to determine the current
position of the stream
Syntax:
int fgetpos (FILE *stream , fpos_t *pos);
Description:
int - return data type
FILE *stream - file pointer name
fpos_t*pos - it is predefined library file in stdio.h
Here pos represent the current position of the file pointer .
5. fsetpos()
The fsetpos() function is used to move file pointer to the
location indicated in pos.
SYNTAX:
int fsetpos( FILE stream , constant value , fpos_t
pos );
73. • fseek(), ftell() and rewind() :
#include<stdio.h>
void main()
{
FILE *fp;
int i;
fp = fopen(“stud.txt","r");
for (i=1;i<=10;i++){
printf(" %d ",ftell(fp));
fseek(fp , 0L , seek_set );
if (i == 5)
rewind(fp);
}
fclose(fp);
}
74. • C provide to give argument or input through
command line (DOS , Linux)
• Here we Pass arguments through commands.
• Till now no argument passed through main()
but in command line argument need some
argument through main() function.
• main() function accepts two arguments
– First argument integer value specifies the number
of command line arguments
– Second argument – list of all of the command line
arguments.
Command line arguments
75. Declarion
list of arguments
int main( int argc , char *argv[])
number of arguments
argv[0]- points first argument
argv[1]- points next argument
Syntax
76. #include<stdio.h>
int main(int argc, char *argv[])
{
int i;
printf(“number of arguments passed=%d” , argc);
for( i=0 ; i<argc ; i++)
printf( “ n arg=%s ” , argv[i] ) ;
return 0 ;
}
Example Program
77. typedef
The C language contains the typedef
keyword to allow users to provide alternative
names for the primitive (e.g., int) and user-
defined (e.g struct) data types.
78. #include<stdio.h>
#include<conio.h>
void main()
{
struct student
{
int rollno;
char name[10];
};
typedef struct student s;
s a;
printf("Enter the student rollno and name ");
scanf("%d%s", &a.rollno, &a.name);
printf("The student rollno and name are n");
printf("%dn%s", a.rollno, a.name);
}