Вы находитесь на странице: 1из 4

C&DS DESD Aug 2012

Assignment-5 (strings,structures & unions): -


Strings
Implement your own functions for reading & printing strings
Define your own functions for
a) finding length
) copying
c) concatenation
d) comparision
e) re!ersing in memory
Study the following functions
strncpy" strncat" strncmp" strcasecmp" strncasecmp" strchr" strrchr"strstr" strto#
E$plore the following functions used for raw memory operations%
memcpy" memcmp" memset" &ero
Implement your own function to con!ert a string ha!ing only digits into an integer and !ice
!ersa
'rite a c program to find sum & a!g of command line arguments
In a tale of strings swap any two rows" when tale is declared as
a) char tstr()*(20*+
) char ,tstr()*+
Con!er the string in a%%c%d format into -2 it unsigned integer .use pointer operations for
pac#ing purpose)
'rite recursi!e functions for
a)finding string length
)displaying string in re!erse order
c)to count no%of occurences of a gi!en character
d)finding su string in a main string
CDAC AC/S" 0une 1
C&DS DESD Aug 2012
Structures & Unions
Create a structure for student information with the memers rollno" names"
mar#s" and perform following operations
1 Creating !ariales" input" output operations
1 initiali&ation of !ariales
1 create a pointer of struct type" and assign address of !ariale
1 access memers using arrow operator
1 calculate si&e of !ariale" offset of each memer
1 create alias for the structure type" pointer type using typedef
2or the following structure calculate o!erall si&e" offset of each memer%
3ow to alance etween speed" memory while using such structures%
struct A 4
int $+
char c1+
doule d+
float f+
char c2+
5
Create a 6o$ structure with the memers length"readth"height%0ass the structure !ariale to
a function to calculate !olume y !alue" y reference
7 In the student structure creatd ao!e modify mar#s memer as an array.array
of ) su8ects)" create array of struct !ariales and do some input"output
operations%.9ar#s of ith student in 8th su8ect etc)
7 'hats wrong in the following code" suggest a fi$ for this%
strcut A
4
int $+
char ,str+
5+
struct A a1 : 4 101" ;ac< 5
CDAC AC/S" 0une 2
C&DS DESD Aug 2012
struct A s2 : a1+
Can a function return structure !ariale=Any etter alternati!es to this if it is possile or not%
Create an anonymous structure" create some !ariales from this .with & without typedef)
Create a nested structure" access memers of inner structure from outer one%
6it fields
Unions:-
/ry the following code
union A
4
int $+
int y+
char ch+
5+
union A a1+
a1%$:0$10+ a1%y:0$1121+ print a1%$" a1%ch
Calculate si&e of union " offset of memers
Con!ert ip address etween dotted decimal format" -2 it format using unions
Anonymous unions" usage of typedef
>esting of structures" unions
7?nion inside a structure
7structure inside an union etc%
Miscellaneous:-
Precision problems
Compare some int" float" doule e$pressions" if getting precision prolems
rectify using the condition fas.e$p1 7 e$p2) @ 1e1)
egA1 int $ : 2+ float y : sBrt.C)+ float &:sBrt.0%122))+
Chec# correctness of comparisions li#e $::y " &::0%-) etc%
Buffered !" operations
int a""c+
CDAC AC/S" 0une -
C&DS DESD Aug 2012
printf.;enter two no%sDn<)+
scanf.;<EdEd<"&"&)+ FFut here gi!e input of - no%s separated y space%
printf.;ente ranother numerDn<)+
scanf.;Ed<"&c)+
printf.;Ed"Ed"EdDn<"a""c)+
'hat do you oser!er" if any pro fi$ it using ; Ed< while reading !ariale c
.or) use GGfpurge efore reading c
char c1"c2+
printf.;enter any characterDn<)+
scanf.;Ec<"&c1)+ FFyou may use getchar.c1)+ here
scanf.;Ec<"&c2)+
printf.;c1:Ed"c2:EdDn<"c1"c2)+
fi$ any pro using a space efore Ec or using GGfpurge
int $"y+
for.int i:1+i@:)+iHH)
4
printf.;i:Ed<"i)+ FFdont use Dn at end of printf
y:1F.$1))+
5
'hat do you oser!er when you run ao!e code%
/ry the same using Dn at the end of printf or y using fflush after printf
CDAC AC/S" 0une C

Вам также может понравиться