You have an int array with n elements and a structure with
three int members.
ie
struct No
{
unsigned int no1;
unsigned int no2;
unsigned int no3;
};
Point1.Lets say 1 byte in the array element is represented
like this - 1st 3 bits from LSB is one number, next 2 bits
are 2nd no and last 3 bits are 3rd no.

Now write a function, struct No* ExtractNos(unsigned int *,
int count)
which extracts each byte from array and converts LSByte in
the order mentioned in point1.and save it the structure
no1, no2, no3.

in the function struct No* ExtractNos(unsigned int *, int
count), first parameter points to the base address of array
and second parameter says the no of
elements in the array.

For example: if your array LSB is Hex F7 then result no1 =
7, no2 = 2, no3 = 7. In the same way convert all the
elements from the array and save the result in array of
structure.

Answers were Sorted based on User's Feedback



You have an int array with n elements and a structure with three int members. ie struct No { ..

Answer / vadivelt


#include<stdio.h>
struct No* ExtractNos(unsigned int *p, unsigned int count);

struct No
{
unsigned int no1;
unsigned int no2;
unsigned int no3;
};

void main()
{
unsigned int array[20],*p, count, i;
struct No *r;
printf("ENTER THE NO OF ELEMENTS IN THE ARRAY: \n");
scanf("%d", &count);

printf("ENTER TH ELEMENTS IN THE ARRAY:\n");
for(i = 0; i<count; i++)
{
scanf("%d", &array[i]);
}

p = &array[0];
r = ExtractNos(p, count);
printf("\n");

for(i = 0; i<count; i++)
{
printf("ELEMENT IN THE STRUCTURE %d \n", (i+1));
printf("NO1: %d\nNO2: %d\nNO3: %d \n\n", r->no1, r->no2, r-
>no3);
r++;
}

getch();
}

struct No* ExtractNos(unsigned int *p, unsigned int count)
{
int i;
struct No *q;
q = (struct No*)malloc(sizeof(struct No)*count);
if(p != NULL && q != NULL && count > 0)
{
for(i = 0; i<count; i++)
{
q->no1 = (*p & 0x07);
q->no2 = (*p & 0x18) >> 3;
q->no3 = (*p & 0xE0) >> 5;
q++;
p++;
}
}
return (q - count);
}

Is This Answer Correct ?    3 Yes 0 No

You have an int array with n elements and a structure with three int members. ie struct No { ..

Answer / vadivel t

Hi small mistake.

change the
printf("ELEMENT IN THE STRUCTURE \n", (i+1));
to
printf("ELEMENT IN THE STRUCTURE %d\n", (i+1));

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C Interview Questions

Is c is a low level language?

0 Answers  


Why c is called a middle level language?

0 Answers  


Explain what is a pragma?

0 Answers  


What is a spanning Tree?

1 Answers   TCS,


What are the c keywords?

0 Answers  






wap in c to accept a number display the total count of digit

4 Answers  


Why main function is special give two reasons?

0 Answers  


What do you mean by dynamic memory allocation in c?

0 Answers  


#include show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf(" %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }

0 Answers   Wilco,


Symmetric technologies interview questions. For Computer science candidates the first round is a objective type written test consisting of 16 questions.It is very easy ,any police man can solve this. And next round is a written test consists of both objective and subjective .Total 40 question related to c,c++ and operating system related questions. And then a technical interview and give some program to solve with computer.The md is adamant person, whatever he says we have to accept that is the condition. And one more thing ,,,these interview is just for a formality..the company will select only innocent guys.. the person's without a backbone only they require.. And u have to submit the certificates this is the most important problem...So if you are not getting any other jobs..then only join with this... It is better to try for other company...And apart from that symmetric do a lot of projects..If a candidate can manage everything u can join and make good career with this company... The Md will normally speak rudely..but he is good person and he will give you a lot of very good chances to improve your career....but with cheap salary....

0 Answers   Symmetric Technologies,


How can you tell whether a program was compiled using c versus c++?

0 Answers  


What are the different flags in C? And how they are useful? And give example for each in different consequences?

1 Answers  


Categories