Improve company productivity with a Business Account.Sign Up

x
?
Solved

Errors

Posted on 2004-08-02
10
Medium Priority
?
459 Views
Last Modified: 2010-04-15
Can someone quickly fix the errors in the following for me:


typedef unsigned int size_t;
typedef struct {
int      _file;                  int      _flag;                  unsigned _bufsiz;            char      *_ptr;                  int      _cnt;                  char      *_base;            } FILE;
extern      FILE _files[32];
FILE *fopen(char *name, char *mode);
int   fclose(FILE *fp);
int   fread(void *buf, int sizelem, int n, FILE *fp);
int   fwrite(void *buffer,int sizelem, int n,FILE *fp);
int   feof(FILE *fp);
int   ferror(FILE *fp);
int   fflush(FILE *fp);
void  clearerr(FILE *fp);
int   fseek(FILE *fp,long offset,int origin);
long  ftell(FILE *fp);
int   fscanf(FILE *fp,char *format,...);
int   scanf(char *format,...);
int   sscanf(char *buf, char *fmt, ...);
int   fprintf(FILE *fp, char *fmt, ...);
int   printf(char *fmt, ...);
int   sprintf(char *buf, char *fmt, ...);
int   vsprintf(char *buf, char *fmt, char *args);
int   fgetc(FILE *fp);
char *fgets(char *buf, int n, FILE *fp);
int   getc(FILE *fp);
int   getchar();
char *gets(char *buf);
int   ungetc(int c, FILE *fp);
int   fputc(int c, FILE *fp);
int   fputs(char *str, FILE *fp);
int   putc(int c, FILE *fp);
int   putchar(int c);
int   puts(char *str);
int main(void)
{
printf("%d = in us dollars"\n);
printf("%d australian = 0.701740 %f usd"\n);
printf("what amount is austrailia"\n);
printf("%d jamaican = 60.0500 %f usd"\n);
printf("what amount is jamaican"\n);
printf("%d african = 545.872 %f usd"\n);
printf("what amount is african franc"; \n)
printf("%d bahamas = 1.00000 %f usd"\n);
printf("what amount is bahamas"\n);
printf("%d germany = 0.832159 %f usd"\n);
printf("what amount is germany"\n);
printf("rates as of august"\n);  
return 0;
0
Comment
Question by:objects
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 11

Assisted Solution

by:avizit
avizit earned 400 total points
ID: 11700451
1. why are you writing the prototypes of all the standard functions , you can just include the <stdio.h>

2. You need to read up more. The printf function is not used the way you are using.

e. g of correct usage

printf("Hey");

this will print Hey  

printf("hey\n");

this will print hey and also append a new line at the end

printf("an example of an integer is %d",12);

this will print an example of an integer is 12

overall you need to get a good C book and study and start from scratch as in from the
"hello world" program.

0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 800 total points
ID: 11700544
#include<stdio.h>
int main(void)
{
printf("%d = in us dollars\n");
printf("%d australian = 0.701740 %f usd\n");
printf("what amount is austrailia\n");
printf("%d jamaican = 60.0500 %f usd\n");
printf("what amount is jamaican\n");
printf("%d african = 545.872 %f usd\n");
printf("what amount is african franc \n");
printf("%d bahamas = 1.00000 %f usd\n");
printf("what amount is bahamas\n");
printf("%d germany = 0.832159 %f usd\n");
printf("what amount is germany\n");
printf("rates as of august\n");
return 0;
}

%d, %f etc in printf are format specifiers ... you need to supply the variables/data whose format you are specifying ... something like
printf("%d germany = 0.832159 %f usd\n"1,0.5);
or
printf("%d germany = %f usd\n"1, 0.832159);
or using variables
printf("%d germany = 0.832159 %f usd\n"ger,ger*0.832159);
ofcourse you need to declare and initialize ger before using it
0
 
LVL 8

Expert Comment

by:ssnkumar
ID: 11700710
What is the problem statement?

-ssnkumar
0
Building an Effective Phishing Protection Program

Join Director of Product Management Todd OBoyle on April 26th as he covers the key elements of a phishing protection program. Whether you’re an old hat at phishing education or considering starting a program -- we'll discuss critical components that should be in any program.

 
LVL 5

Expert Comment

by:lwinkenb
ID: 11700969
I think sunny missed some commas in his printf examples.
printf("%d germany = 0.832159 %f usd\n"1,0.5);
should be
printf("%d germany = 0.832159 %f usd\n",1,0.5);
(notice the comma after the second pair of quotes).


0
 
LVL 9

Assisted Solution

by:ankuratvb
ankuratvb earned 400 total points
ID: 11700970
Hey,

its objects of Java fame.

In addition to the above comments,You might need to get input from the user.

For that you'll need to use scanf().

The syntax is pretty similar to  printf.

int i;
scanf("%d",&i);

To print the value of i,use printf("Value of i:%d",i);
0
 
LVL 92

Author Comment

by:objects
ID: 11700989
Thanks people, and apologises for my laziness :)
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 800 total points
ID: 11700991
>I think sunny missed some commas in his printf examples
good catch lwinkenb ...

hey objects,
this might interest you
http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_21078242.html
0
 
LVL 5

Assisted Solution

by:lwinkenb
lwinkenb earned 400 total points
ID: 11700999
Here is a little example to get you started in the right direction objects...

#include <stdio.h>
#include <stdlib.h>

int main()
{
      char buff[64];
      float fDollars_us;

      printf("Program starting...\n");
      printf("How many dollars in US currency?:  ");
      gets(buff);
      fDollars_us = (float)atof(buff);
      printf("\nYou entered in %f US dollars\n",fDollars_us);
      printf("In Australian this is %f\n", fDollars_us * 0.701740f);

      return 0;
}
0
 
LVL 92

Author Comment

by:objects
ID: 11701006
I've lot all I need, thanks all :)
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11701010
for the umpteenth time ;o)

*dont* use gets ... use fgets instead ....
0

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

595 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question