473,395 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Someone To Debug My Prog!!!!

momotaro
357 100+
am supposed to fill an array of structure with some info and retreive it ....
what is wrong with my code! plz help!


Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. typedef struct
  4. {
  5.     char name[20];
  6.     double salary;
  7.     int rank;
  8. }employee;
  9.  
  10. void fill_array(employee);
  11. employee display(employee);
  12.  
  13. void main()
  14. {
  15.     employee arr[2], e;
  16.     fill_array(arr[2]);
  17.     e = display(e);
  18.     while(1);
  19.  
  20. }
  21.  
  22. void fill_array(employee arr)
  23. {
  24.     int i;
  25.     for(i = 0; i<2; i++)
  26.     {
  27.         printf("name --> ");
  28.         scanf("%s", arr[i].name);
  29.         printf("salary --> ");
  30.         scanf("%lf", arr[i].salary);
  31.         printf("rank --> ");
  32.         scanf("%d", arr[i].rank);
  33.     }
  34. }
  35.  
  36. employee display(employee e)
  37. {
  38.     employee arr[2];
  39.     int i;
  40.     for(i = 0; i<2; i++)
  41.     {
  42.         printf("\n\n\n\nname --> ", arr[i].name);
  43.         printf("\nsalary --> ", arr[i].salary);
  44.         printf("\nrank --> ", arr[i].rank);
  45.     }
  46.     return e;
  47. }
Feb 10 '07 #1
4 1048
horace1
1,510 Expert 1GB
fixed a few errors, I think fill_array() is working - you now need to work on display()
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. typedef struct
  4. {
  5.     char name[20];
  6.     double salary;
  7.     int rank;
  8. }employee;
  9.  
  10. void fill_array(employee[]);
  11. employee display(employee);
  12.  
  13. int main()
  14. {
  15.     employee arr[2], e;
  16.     fill_array(arr);   // ** removed [2]
  17.     e = display(e);
  18.     while(1);
  19.  
  20. }
  21.  
  22. void fill_array(employee arr[])  // ** added []
  23. {
  24.     int i;
  25.     for(i = 0; i<2; i++)
  26.     {
  27.         printf("name --> ");
  28.         scanf("%s", &arr[i].name);  // ** added &
  29.         printf("salary --> ");
  30.         scanf("%lf", &arr[i].salary);
  31.         printf("rank --> ");
  32.         scanf("%d", &arr[i].rank);
  33.     }
  34. }
  35.  
  36. employee display(employee e)
  37. {
  38.     employee arr[2];
  39.     int i;
  40.     for(i = 0; i<2; i++)
  41.     {
  42.         printf("\n\n\n\nname --> ", arr[i].name);
  43.         printf("\nsalary --> ", arr[i].salary);
  44.         printf("\nrank --> ", arr[i].rank);
  45.     }
  46.     return e;
  47. }
  48.  
Feb 10 '07 #2
momotaro
357 100+
thx! this is the worked out version with still one error!:
Error 4 --> error C2143: syntax error : missing ';' before 'type'
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. typedef struct
  4. {
  5.     char name[20];
  6.     double salary;
  7.     int rank;
  8. }employee;
  9.  
  10. void fill_up(employee arr[]);
  11. void display(employee arr[]);
  12.  
  13. void main()
  14. {
  15.     employee arr[2];
  16.     fill_up(arr);
  17.     display(arr);
  18.     while(1);
  19. }
  20.  
  21. void fill_up(employee arr[])
  22. {
  23.     int i;
  24.     for(i = i; i < 2; i++)
  25.     {
  26.         printf("name --> ");
  27.         scanf(" %s", &arr[i].name);
  28.         printf("salary --> ");
  29.         scanf("%lf", &arr[i].salary);
  30.         printf("rank --> ");
  31.         scanf("%d", &arr[i].rank);
  32.     }
  33.  
  34. void display(employee arr[])  <-- error missing ';'
  35. {
  36.     int i;
  37.     for(i = i; i < 2; i++)
  38.     {
  39.         printf("\n\n\n\nname --> ", &arr[i].name);
  40.         printf("\nsalary --> ", &arr[i].salary);
  41.         printf("\nrank --> ", &arr[i].rank);
  42.     }
  43. }
Feb 10 '07 #3
Ganon11
3,652 Expert 2GB
thx! this is the worked out version with still one error!:
Error 4 --> error C2143: syntax error : missing ';' before 'type'
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. typedef struct
  4. {
  5.     char name[20];
  6.     double salary;
  7.     int rank;
  8. }employee;
  9.  
  10. void fill_up(employee arr[]);
  11. void display(employee arr[]);
  12.  
  13. void main()
  14. {
  15.     employee arr[2];
  16.     fill_up(arr);
  17.     display(arr);
  18.     while(1);
  19. }
  20.  
  21. void fill_up(employee arr[])
  22. {
  23.     int i;
  24.     for(i = i; i < 2; i++)
  25.     {
  26.         printf("name --> ");
  27.         scanf(" %s", &arr[i].name);
  28.         printf("salary --> ");
  29.         scanf("%lf", &arr[i].salary);
  30.         printf("rank --> ");
  31.         scanf("%d", &arr[i].rank);
  32.     }
  33. }
  34.  
  35. void display(employee arr[])  <-- error missing ';'
  36. {
  37.     int i;
  38.     for(i = i; i < 2; i++)
  39.     {
  40.         printf("\n\n\n\nname --> ", &arr[i].name);
  41.         printf("\nsalary --> ", &arr[i].salary);
  42.         printf("\nrank --> ", &arr[i].rank);
  43.     }
  44. }
You were missing a single '}' to end your fill_up function...I've added it.
Feb 10 '07 #4
momotaro
357 100+
THX !!! but am supposed to have the info that i ve put in the array to be be printed back but it does not happened!
Feb 10 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mike Chirico | last post by:
Hopefully this will help someone... Helpful Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Last Updated: Fri Apr 16 11:47:34 EDT 2004 The latest version of this...
0
by: Yannick | last post by:
Hi, I have a small app in VB that implements a C++ OCX I would like to debug the OCX from VB prog or even better debug both at once ! I was able to do this in visual studio 6 by referencing the...
0
by: jhorner | last post by:
I am writing a c# app and need the ability to drag a file onto the icon - this should then run the app and do something with the file. I made the assumption that doing so would call the app with...
13
by: Jason | last post by:
Could someone here show me how I would write a vb program to convert decimal ip address to binary? For example a small form with a convert button and a label for the result and a textbox for the...
6
by: Boni | last post by:
Dear all, I have following problem. I created a static libruary (mylib.lib). I compiled it with Multithreaded DLL runtime in release mode. Now I want to give out this library. But users who...
1
by: ניר | last post by:
Hello, I've already sent such a messege, hopping to be answered shortly this time. I am practicing c/c++ programming using microsoft visual c++ express 2005 express edition. Anyway, unlike other...
4
momotaro
by: momotaro | last post by:
when I give the prog the first data it crushs !!!! and give me this message: Unhandled exception at 0x004114c5 in CallocMalloc.exe: 0xC0000005: Access violation reading location 0x00000002. ...
2
momotaro
by: momotaro | last post by:
This is what am i asked to do: Implement a priority queue to manage patients in an emergency room You MUST use the files “patient.h” and “ER.c” as given. You should write the files...
1
by: davy zhang | last post by:
I mean every process attach like thread in wingide like thread or tasklet in wingide :) maybe I asked toooo much:D
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.