0% found this document useful (0 votes)
8 views11 pages

PPSC Assignment

The document discusses string handling functions in C programming, including standard library functions for manipulating strings such as concatenation, comparison, and conversion between cases. It also covers dynamic memory allocation using functions like malloc, calloc, and realloc, explaining their usage and syntax. Additionally, the document touches on file handling, including copying and deleting files, and highlights the differences between text and binary files.

Uploaded by

goganidinesh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

PPSC Assignment

The document discusses string handling functions in C programming, including standard library functions for manipulating strings such as concatenation, comparison, and conversion between cases. It also covers dynamic memory allocation using functions like malloc, calloc, and realloc, explaining their usage and syntax. Additionally, the document touches on file handling, including copying and deleting files, and highlights the differences between text and binary files.

Uploaded by

goganidinesh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Nosne v, artosh kurnar

ESE

Owhat 1s sting Exolain ing Hondlin functions


utth example soqrom?
Stuinq 1s a collec tioo of chosacie Co)
AD o choxactess the t i n n c lanquaqe is
ne dermenstona axsa O4 c h a . o h i c h 13 4emimie

by D (o) null chouacter.

Sntax cdata type Vovíablename [izé);


chor Voxghox Csize),
es cho Sto)
Standard ibsory sting fumtions
Win ever Compliar

olarqe set od usetul stinq hondling ibrary


unctins are xovided o usinq thesë +uncionS
we need to nclude the heade e strinq.h".
tunction Use
tind h e Length or tne
OO Strlenc)
S tSt CPytC
Stingtooy
fo A angmer string Yariable.
s t r Catc) tOo combin d (o) join,
Str (met) Compares tuoo StrinYS.
evetSes the iven Strin
Convet a strinq TU Louser (ase.
5t Luor ()
t t Up«C ) chone to uPpe Case.
Count Number ot Characted
Stu len TKis tunc tion the

present
he qiven Strin.
4tinclude < Stáiohy

i n c k u d e <conio.n7

maint)

cho nam26)
nt Len
Dinty enter astrinq),
gets Cname),

Len = Str l e n name)


tuen sttinq 7d,len)
print Tenath
2
Content ot One

Stipu mis nction copi e $ the


stiing intd another
tincde <[Link]

ttinclude ehao
mainc

cha St [io, Strio],


pintt enter astring%
ets CSt)
StsCpy (str2 Sta)
Puts CStr2),

I t Cansist
Str cat Tt combinds tuoo Stings.
at the end oF dtstiet
Concateate te Soxce string
Strinc.
tinciu&e<[Link]

ineude stum.
mainc)

Char Stl20), sts2(zo)


a
St string;
prntyenter
ets CSt);
2nd stin
priati N enter

get Cstra),

str cat CSt iSts);


Puts s t ) ,
t
too i 4ind
m d out wheather
Compares
two stings
Stings
ou

Sticmp T4 stuingsS
tuoo
the toD Stsinq
ther are Same (ox)different there
c haracter until
Compared cnaratter
by
mis m atch Covd end o the Strings is
eathed
Ex-ttintlud e <stdioh
include c S1iinhy
mainC)

cha Str1{1o), stm(20];


int
Prints enter a 1st string
ets (Stt)
Qint enter a 2nd siuin")
ets (s4r 1)
0 Strme lsirSto)
(n==o)
Pait ( strings ave same)
else
pintsStrinqs ae aifferent )

StvevC ThiS tunttiom use to veYerse ot he gNen stir-


nclude 4stdfo.n
ntlude <sttimh
Maint)

has St[io)
prints enter a Strinq")
ets CStr)
Sttbev (3t1)
puts St1)

Sttlwr C ) T t con ver ts upPer case tunction to lower Case.


tidudelstsio.h
indude < strirq.h
main)

Cha sto],
Pomtt Center a Stn)
ge ts(stt)
Stlor (str1);
Piinty ower caLse s , strl
E xplain pointer to poiater Conept ?

we Can also dedased a Pointer var iable to


to
Pointer Variable.
Point 4ind ano ther

to example Ponter it
Tnt PO1oter

indicates thot Pis a Pointer hat Points


anothe pointer,
contains the address of another
Poimter vat iable
Pointex s Called Poiter to 0omtes.

include <Stdiohr
maint )

P4a
P,
Printt zd, ¥* )

AllOCation? Explain ditHerent


what is Dynamíc memory
ha t allotations i t h example s.
tyoes of
ot memory
tyoes
Dunamiic Memory qllocation Ttuses pvedetined
A
allocate cand elease memoy tos
functions tD
data while the 0gam is sunnin
a nami memory allo catio0 the memory

Otbe allocate in heapmemory,


The memot alloCa teed in fhe heap 00ly

Pointer, TO aess data in


thsou
e MUSt use Ponter.
dynamic memory CA
O

memos ollOcution -tunctions


These ave three memy allocation fundtions

allocating memo namically in c.


t
hey ate malloctc ) D callocC) Gr) Åeall).

dmalloc The malloc) allpcotes Sinqle bloxk


Contuins h e Number of bits
O memo
memorythat
in ts Paramatex, Tve callocated Ymemory
SPeitie
i Aot initalizes
Syntax- size ot (dadatype)
= Cdota fyoe*)malloc Cn
Pointe Nasiable of
YeturnS the addiesS
addresS o tist
+irst
The malloc c )
allocatri
Space
in the memo
on tilure.
the Null poimter
etuNS

<stdto.h>
t intlude
Ex + î n c l u d e <[Link]

mcint
n, 0 ,Sum=0
tnt elemets" )
numbes o
Printtentes
Scant %d,&0)
P- tmallot (n4
ze oftint)
4(P-=NulL)
n t allo(ated);
o t alldtated );
memosy
Prirtt essos
exitCo)
elements o o a u
PRnty entes
for (-o in,iH)

Scani. a" P),


Sum t X (Pti),

Pint Sum 7,d", Sum)


allocafe the memory
Calldc me Callot ) also
mallbc
'.
to allocates
Similia s that malloc
The diHeente

secce
CalloC) a locatey
blbck o sfovage Same
a Sinqle eah ot the
multile ocKs Of Stosaqe

Size
4 i n c l u d e S t d i o . h y

tib»hy
tindude < S4d

maint)

n 1,40 rC, mns');


nt H owS & colu
Printt C e n t e r numer

P= int ) calloc
(xC* sizeot (Tnt),
elements "
p intt enter
3itAy
t o Cfeo, <v*
scand 7.,P41,
3 elements
ae ),
ven
Ptt C
The

Fo J 0 JLt,JH)
oH),
Priwtt C , d t *
ointsn"),

Ts o Teallocation o oi
Dealloc) The
The
realloc)
Size bt 1he
the
chane s the Size
tunction chane e emo
mo1Y
memoYy
tis
extentin
he
the
o
deletin
block y blotk
end ot the Blotk
at fhe

Syntax
Realloc (Pointer Variable,Newize
Pointes Vaslable =atatyoe")
nclude k [Link]
i n c (ude Stdlibh>

maint)
Cchar* )mallbe(
(0),
S
t c p y ( s * Hello")

Cchax) reallo ( 5/20)


S
Ce

pvint NZ5", 5)

a coal Recussi0n
Recurssion ? Eplain Aacorial
ohat Is
G|
t bonaci Recursion1
AnS fun tion calls tseH sepeati ly
RecussibyTne ecni Ts
.This
Knoun as
Recurssion tun tion
Knouon Cs Recurssion.
ecursSsfon
ecGYSSTon
numbey
Ex actoial gta qiven
include [Link]
int fact Cint)
maind
int

Nente m vallue),
Pont
Scan %S",&n);
a t t (n,
rinty"he dattovul
is sd", act (n)

tnt a t Cint n)

int i
4([Link]==t)
vetum
else
Ye tun m x a t (n-1);
etun 3
abbornacti Series
[Link]
+tinclude <
int tab int),
main ()

nt n element.
he numbev o
Print ( ente
Scanbt (7."&n
pTintt Abona ci series");
intst7d or)
Pratt
for (1o ien, it+)

printt % ib(t)),

int fRb(int n)

se tusn o'
else 1 (n==1)

else
setun (41bCn-1)4REC0-2))

+le and
ohat isfile1 Explain
tet +le 6 Binary
diteences bluw ext ile&Binary le?

ntosmation
n tomation sto«ed
stoes
Ans e A
A tle 1s a
collection ot

Some uwhere othe than primory store


collection o data
A ile a extesnal

as unt
tseated
that
That Can be
Set ot e cord s
file iS a

the Set of lbrasytunc tions


aceSSed
thso u
to Store intovmotion pemanentty
allbuw us
4iles be ccesseed and it Can
ond can
+ile Can
disk. Thís
n the
de pendin upon the equireme nt.
altese
be
THpes ot 4iles' ntd
n o too ypes
Categovised
Ailes
*iles e re
a pimaily
text iles )Binas Res

Test iles ntomation Like dchabeds,


tike aphabets,
4ile Stoves textua
A text text files have
Special Sumbols e t t . These
numbeYS
the named
the exten`iDn txt.n

Ex [Link] [Link].
Binary 4iles tomaion in binary tom
Stores the
ABinaay4ile
whereas
wee Aaed not Convert he binary files
ConNersion
som text iles Ao
txt Files nees
binouy filex.
data in the
iles hich Stre
Any
as binary ile.
bytes is Knouon

Files psoqrams
Copy ile
one to another +ile
)moqe ile
3 delete +ile porams
Ans Coo one ile to anotherie
tinclude< [Link]
[Link]
tinclude< [Link]
main)

FILE *fpl,*¬p2
chax ch,
F pl = Foçen input.c",'r');
f p2 fopen output.c, " w")
4HP ==NULL|| FP2== AlDLL)

Pinty (tould not Dpen files");


eit o)

while I )
Che qetC (pL,
Cch= =EOF)
break
else
Putckhf)

Prnty Filed Cooied Sucesstully"),


close fPI),
+close ({fpi),
getch

2meqeS tuo0 4iles'


#ntlude kStatohy
+includeitonio.h
includes stdth
maint

FILE pl, *fP,**P3


Cha ch
c SCrC
+PIEFopen (nput.c"",
fP2 4oden
=
outeut .c, ");
+3ftpennew.C, w');

Pat Could
exitto
not oen+iles

while CC ch= qetc GrD) L EOF)


Aatth Ceh ,fo3),
ohile Cccheqetc(EP2) \= bof)
putc (chEo>)
priott Merqed 10put And out [Link] new .c")
fcktse fo;
ctOse (fPi)
4close (E33,
getch)
Aelete a ffle
wniie a c psoam t
intludezstaio.h
4 intlude cconiO,hy
Main

int stotus,
chor flename )

tile uwish to delete n")


Pint enter the name o
ets lenamel,
s tatus = removeCtilename),

Cstatus ==o)
PrTnttC7.s tile deleted Sucesstully n", triename);
else

pvinti unable to deleie the ile \n");


Peos ( exior");

You might also like