Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-27-2008, 06:08 PM
esmeco esmeco is offline
Newbie
 
Join Date: Mar 2008
Posts: 1
Credits: 0
Rep Power: 0
esmeco is on a distinguished road
Default Array of structures problems

Hello!

I'm currently working on a project and I'm having a bit of an hard time with two functions in specific:

Function 1:In this function I want the doctor's number of patients to increase after patient has consulted that doctor.
As so,by means of testing the function,in the menu, I add a doctor to the array of doctors and then I add a patient.In the patient fields that are asked in program(name,age,address), I fill the field name of the doctor with the doctor that
treated/will treat him.
After that,I check the doctor's data and the number of patients has indeed increased by one.

Problem:


If I add another doctor and add another patient,and in the patient's doctor name field I add the new doctor name,in the doctor's data,instead of just incrmenting the new doctor's patient it increments the new doctor's patient and the other doctor!

Code:

Code:
void addpatients_to_doctors(Doctors array_of_doctors[],Patients array_of_patients[],int ndoctors,int npatients)
{
	int i,z,count=0,x;

	for(i=0;i<ndoctors;i++)      // Goes through array of doctors
	  {
	     for(x=0;x<npatients;x++) // Goes through array of patients
	       {
	               for(z=0;z<array_of_patients[x].nconsultations;z++)  // Goes through number of existing consultations
	                {
		            if(strcmp(array_of_doctors[i].p.name, array_of_patients[x].h[z].doctorname)==0)  //compares the name in the doctor's file with the name of the doctor in the patient's historic consultations 
			      count++;	  
	                }
	             if(count==1)
		        array_of_doctors[i].npatients++;

		     count=0;
	       }
	  }
}

Function 2:In this function I want the patient's historic to have at a maximum 10 consultations from the oldest in the beggining of the array to the newest. After reaching the 10 consultations, the consultation on pos 1 of array will be copied to pos 0,the consultation from pos 2 to pos 1 and from that forward until it reach the last pos where it will have "today's" consultation.

Problem:

This all works alright after I reach the 10 consultations.After that it looks like all the historic is erased and it copies the newwest consultation to teh beggining having only that input on the historic.

Code:
int keep_data_con(Patients array_of_patients[],Doctors array_of_doctors[],int npatients)
  {
	  int i,z,nconsultations;
	  char nid[12];
	  

     printf("Input your id:\n");
	 gets(nid);
	 for(i=0;i<npatients && strcmp(nid,array_of_patients[i].p.npid)!=0; i++);

     if(i==n)
      {
        printf("Patient doesn't exist\n");
        return 0;
	  }
	 else
	 {
	  nconsultations=array_of_patients[i].numconsultations++;
	  if(nconsultations==10)
	    {

		  for(z=0;z<nconsultations;z++)
			array_of_patients[i].h[z]=array_of_patients[i].h[z+1];	

       array_of_patients[i].h[numconsultations-1]=get_data_conultations(array_of_doctors,npatients);
	    }
	  else
        array_of_patients[i].h[numc]=get_data_consultations(array_of_doctors,npatients);
	 }
}
Any help on this is very appreciated!Thanks in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-28-2008, 11:32 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,385
Last Blog:
wxWidgets is NOT code ...
Credits: 662
Rep Power: 27
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: Array of structures problems

Maybe it's just me, but not having all the classes/structs defined in your code is making it harder to determine what your code is trying to do. What is Patients and Doctors?
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Array manipulation Question in C++ JJJIrish05 C and C++ 1 03-08-2008 02:06 PM
Problems passing a serialized array in a session variable gszauer PHP Forum 3 02-15-2008 11:18 AM
Usage of array structures to increment letter instances of text Yuriy M C and C++ 2 09-13-2007 10:49 AM
fread into array position kenna C and C++ 0 08-17-2007 08:03 AM
Python 2D array question annannienann Python 3 04-23-2007 04:36 PM


All times are GMT -5. The time now is 09:42 PM.

Contest Stats

Xav ........ 1024.41
MeTh0Dz|Reb0rn ........ 974.08
morefood2001 ........ 850.04
John ........ 841.93
WingedPanther ........ 661.52
marwex89 ........ 575.59
Brandon W ........ 447.33
chili5 ........ 292.12
orjan ........ 187.41
Steve.L ........ 180.25

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 79%

Ads