Solved

Errors

Posted on 2004-08-02
10
448 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 100 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 200 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
 
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 100 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 92

Author Comment

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

Assisted Solution

by:sunnycoder
sunnycoder earned 200 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 100 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now