[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: help!



Dear Chetan,

Another alternative could be u use a linked list of Float and pass the header
to the function. You can count the nmber of nodes in the Linked List too. It
would require more programming but wud solve ur prob. I've made a small program
hope it will solve ur prob.

Goldwyn :o)


chetan dutta wrote:

> Hi!
>
> i am writing a c fx with variable # of arguments, declared as
>
> int my_func(int a, char b,...);
>
> the problem is va_arg()(declared in  stdarg.h) can not handle floats, it can
> handle int, char * etc
> and my_func() needs to handle variable number of float args,
> how can i use float in a function with variable number of args?
>
> please suggest me a way around to handle this problem.
>
> chetan
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
> Share information about yourself, create your own public profile at
> http://profiles.msn.com.
>
> ------------------------------------------------
> The mailing list archives are available at
> http://lists.linux-india.org/cgi-bin/wilma/linux-delhi
#include<stdio.h>

struct flp
{
float d;
struct flp *next;
};

struct flp *CreateList()
{
char ch='y';
float f=1;
struct flp *first=NULL,*p, *p1;
printf("\n\nEnter the Floating Point Number and hit Enter\n");
while (ch!='n')
{
printf("\nEnter the Floating Point Number : ");
p = (struct flp *)malloc(sizeof(struct flp));
p->next=NULL;
scanf("%e",&f);
p->d=f;
if (first==NULL) first=p;
else p1->next=p;
p1=p;
printf("Any More (y/n) : ");
scanf(" %c",&ch);
}
return(first);
}


void PrintList(struct flp *first)
{
struct flp *p;
int i=0;
p=first;
printf("\n\nThe List is :\n\n");
while (p!=NULL)
{
printf("%f\n",p->d);
i++;
p=p->next;
}
printf("\n\nThe number of Arguments are : %d\n",i);
}

int main()
{
struct flp *first;
first=CreateList();
PrintList(first);
return 1;
}