Solved

Errors

Posted on 2004-08-02
10
452 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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
 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

808 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