Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > scan float pointers

Reply
Thread Tools

scan float pointers

 
 
ehabaziz2001@gmail.com
Guest
Posts: n/a
 
      12-10-2005
Hi,
I runned that program with int variables and was OK but when I changed
the type of
pay_calc(),*emp_rate,pay
from integer to float I failed ..Please Help

main()
{
int *emp_no,*emp_works;
int pay_calc(),*emp_rate,pay;
char *emp_unit,ans,another();
system("cls");
do {
input(&emp_no,&emp_works,&emp_rate,&emp_unit);
pay=pay_calc(emp_works,emp_rate,emp_unit);
pay_slip(emp_no,emp_works,emp_rate,emp_unit);
cash(pay);
} while (another()=='y');
return 0;
}


char another()
{
char answer;
printf("\nAnother Employee (y/n) : ");
scanf("\n");
scanf("%c",&answer);
return (answer);
}


input (emp_n,emp_w,emp_r,emp_u)
int *emp_n,*emp_w;
int *emp_r;
char *emp_u;
{
printf ("\n Enter the Employee number : ");
scanf("%d",emp_n);
printf ("\n Enter the Employee Pay Based unit (weeks or hours) : ");
scanf("\n");
scanf("%c",emp_u);
if ((*emp_u)=='w')
{
printf ("\n Enter the number of weeks :");
scanf("%d",emp_w);
printf ("\n Enter the rate of paying for each week :");
scanf("%d",emp_r);
}
if ((*emp_u)=='h')
{
printf ("\n Enter the number of hours :");
scanf("%d",emp_w);
printf ("\n Enter the rate of paying for each hour :");
scanf("%d",emp_r);
}
return 0;
}

int pay_calc(emp_w,emp_r,emp_u)
int emp_w;
int emp_r;
char emp_u;
{
int p=0.0;
p=(emp_r)*(emp_w);
if (emp_u=='h')
printf ("\nThat pay for hours %d worked with rate %d is =
%d",emp_w,emp_r,p);
if (emp_u=='w')
printf ("\nThat pay for Weeks %d worked with rate %d is =
%d",emp_w,emp_r,p);
return ((emp_r)*(emp_w));
}

 
Reply With Quote
 
 
 
 
Mark McIntyre
Guest
Posts: n/a
 
      12-10-2005
On 10 Dec 2005 03:16:50 -0800, in comp.lang.c , http://www.velocityreviews.com/forums/(E-Mail Removed)
wrote:

>Hi,
>I runned that program with int variables and was OK but when I changed
>the type of
>pay_calc(),*emp_rate,pay
> from integer to float I failed ..Please Help
>
>main()
>{
>int *emp_no,*emp_works;
>int pay_calc(),*emp_rate,pay;


Don't do this. Function declarations should be outside main. Otherwise
their declarations are invisible to other routines.

>printf ("\n Enter the Employee number : ");

?scanf("%d",emp_n);

Do not use scanf to read user input. Please read the FAQ for reasons
why, and what to use instead.

>int pay_calc(emp_w,emp_r,emp_u)
>int emp_w;
>int emp_r;
>char emp_u;


This style of function definition has been deprecated since 1989, that
means you should not use it. Please buy a book on C that dates after
1990 ! This is how you should do it:

int pay_calc(int emp_w, int emp_r, char emp_u)
>{
>int p=0.0;
>p=(emp_r)*(emp_w);


you do not need the parens here.

>if (emp_u=='h')
>printf ("\nThat pay for hours %d worked with rate %d is =
>%d",emp_w,emp_r,p);
>if (emp_u=='w')
>printf ("\nThat pay for Weeks %d worked with rate %d is =
>%d",emp_w,emp_r,p);
>return ((emp_r)*(emp_w));


or here.

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      12-10-2005
(E-Mail Removed) wrote:

> I runned that program with int variables and was OK but when I changed
> the type of
> pay_calc(),*emp_rate,pay
> from integer to float I failed ..Please Help


what does "failed" mean? Does it compile? Does it give unexpected
answers?

1. double is preferable to int
2. please use a sensible indentation style. I've reformatted one of
your functions
to be more sensible. My remarks are indicated with /***
3. use "int main (void)" not "main ()"

input (emp_n,emp_w,emp_r,emp_u)
int *emp_n,*emp_w;
int *emp_r;
char *emp_u;

/***
this form of function definition has been obselete since 1989
use:
input (int *emp_n, int *emp_w, int emp_r, char *emp_u)
***/

{
printf ("\n Enter the Employee number : ");

/***
use '/n' at the end of use fflush()
***/

scanf("%d",emp_n);

/***
scanf() is tricky to use correctly. Always check for errors and switch
to
fgets() and fscanf()
***/

printf ("\n Enter the Employee Pay Based unit (weeks or hours) :
");
scanf("\n");
scanf("%c",emp_u);

if ((*emp_u)=='w')
{
printf ("\n Enter the number of weeks :");
scanf("%d",emp_w);
printf ("\n Enter the rate of paying for each week :");
scanf("%d",emp_r);
}

if ((*emp_u)=='h')
{
printf ("\n Enter the number of hours :");
scanf("%d",emp_w);
printf ("\n Enter the rate of paying for each hour :");
scanf("%d",emp_r);
}

return 0;
}

--
Nick Keighley

We recommend, rather, that users take advantage of the extensions of
GNU C and disregard the limitations of other compilers. Aside from
certain supercomputers and obsolete small machines, there is less
and less reason ever to use any other C compiler other than for
bootstrapping GNU CC.
(Using and Porting GNU CC)

 
Reply With Quote
 
Michael Mair
Guest
Posts: n/a
 
      12-10-2005
Nick Keighley wrote:
> (E-Mail Removed) wrote:
>
>>I runned that program with int variables and was OK but when I changed
>>the type of
>>pay_calc(),*emp_rate,pay
>> from integer to float I failed ..Please Help

>
> what does "failed" mean? Does it compile? Does it give unexpected
> answers?
>
> 1. double is preferable to int

ITYM double is preferable to float

> 2. please use a sensible indentation style. I've reformatted one of
> your functions
> to be more sensible. My remarks are indicated with /***
> 3. use "int main (void)" not "main ()"
>
> input (emp_n,emp_w,emp_r,emp_u)
> int *emp_n,*emp_w;
> int *emp_r;
> char *emp_u;
>
> /***
> this form of function definition has been obselete since 1989
> use:
> input (int *emp_n, int *emp_w, int emp_r, char *emp_u)
> ***/
>
> {
> printf ("\n Enter the Employee number : ");
>
> /***
> use '/n' at the end of use fflush()


'\n'

> ***/
>
> scanf("%d",emp_n);
>
> /***
> scanf() is tricky to use correctly. Always check for errors and switch
> to
> fgets() and fscanf()

ITYM sscanf()

Note that all functions of the scanf() family return an int
value which denotes the number of successfully read items:
if (1 != sscanf(mybuffer, "%d", emp_n)
{ /* error handling for failed conversion */ }

> ***/
>
> printf ("\n Enter the Employee Pay Based unit (weeks or hours) :
> ");
> scanf("\n");
> scanf("%c",emp_u);
>
> if ((*emp_u)=='w')
> {
> printf ("\n Enter the number of weeks :");
> scanf("%d",emp_w);
> printf ("\n Enter the rate of paying for each week :");
> scanf("%d",emp_r);
> }
>
> if ((*emp_u)=='h')
> {
> printf ("\n Enter the number of hours :");
> scanf("%d",emp_w);
> printf ("\n Enter the rate of paying for each hour :");
> scanf("%d",emp_r);
> }
>
> return 0;
> }
>
> --
> Nick Keighley
>
> We recommend, rather, that users take advantage of the extensions of
> GNU C and disregard the limitations of other compilers. Aside from
> certain supercomputers and obsolete small machines, there is less
> and less reason ever to use any other C compiler other than for
> bootstrapping GNU CC.
> (Using and Porting GNU CC)


Hmmm, is that advertising? In the context of clc, this looks
like "embrace and extend" to me...

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      12-10-2005
Michael Mair wrote:
> Nick Keighley wrote:
> > (E-Mail Removed) wrote:


> >>I runned that program with int variables and was OK but when I changed
> >>the type of
> >>pay_calc(),*emp_rate,pay
> >> from integer to float I failed ..Please Help


<snip>

> > 1. double is preferable to int

>
> ITYM double is preferable to float


yup

<snip>

> > scanf("%d",emp_n);
> >
> > /***
> > scanf() is tricky to use correctly. Always check for errors and switch
> > to
> > fgets() and fscanf()

>
> ITYM sscanf()


yes

<snip>

my error rate seems a little high today...

from my sig:-

> > We recommend, rather, that users take advantage of the extensions of
> > GNU C and disregard the limitations of other compilers. Aside from
> > certain supercomputers and obsolete small machines, there is less
> > and less reason ever to use any other C compiler other than for
> > bootstrapping GNU CC.
> > (Using and Porting GNU CC)

>
> Hmmm, is that advertising? In the context of clc, this looks
> like "embrace and extend" to me...


I didn't post it because I agreed with it. I've never been sure if it
wasn't a bit
toungue in cheek. In no way was it intended to be an advertisment.


--
Nick Keighley

-pedantic
This option is not intended to be useful; it exists only to satisfy
pedants who would otherwise claim that GNU CC fails to support the
ANSI standard.
(Using and Porting GNU CC)



 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      12-11-2005
(E-Mail Removed) wrote:

> main()
> {
> int *emp_no,*emp_works;
> input(&emp_no,&emp_works,&emp_rate,&emp_unit);
>

[snip]
>
> input (emp_n,emp_w,emp_r,emp_u)
> int *emp_n,*emp_w;
> int *emp_r;
> char *emp_u;


You are passing an (int **) to a function that expects an (int *).
This is only the first error I spotted, there could be many more
such errors.

Please use function prototypes, then your compiler will
detect these errors for you.

Example:

int input( int *emp_n, int *emp_w, int *emp_r, char *emp_u );

int main() {
input(&n, &w, &r, &u);
}

int input( int *emp_n, int *emp_w, int *emp_r, char *emp_u )
{
// stuff...
}

If you don't like the thought of writing out the function header twice,
then put the whole function body before main() .

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
float to string to float, with first float == second float Carsten Fuchs C++ 45 10-08-2009 09:47 AM
Best to scan in 48 Bit HDR? Or use 48 Bit + modify during scan? NewScanner Digital Photography 9 01-16-2007 04:07 AM
Progressive scan dvd's on a non-progressive scan tv jack lift DVD Video 7 12-09-2003 06:01 PM
Re: float->byte->float is same with original float image. why float->ubyte->float is different??? bd C Programming 0 07-07-2003 12:09 AM



Advertisments