All right, so I have a final exam due that consists of four problems. I'm currently working on the first problem. I understand the algorithm of the problems, but I am very, VERY weak with syntax and the entire C language in general.

In the first problem, I just indexed the Bloodtype tables (parent parent child) and (parent child parent). Right now, I can open the bloodtype.dat file, but I don't know how to store and parse the characters and make the program read from line to line (loops?). Can someone please help?

Here is the link to the problems, right now I'm working on Problem 1.

Thank you so much!

http://ece15.ucsd.edu/Main/Final.html

Brian

Recommended Answers

All 3 Replies

Post your code. This is an exam, not just homework, so we're going to be even more anal than usual about you doing the work.

This includes the template that I have to write my code on and turn in. Here is what I have so far, I don't know how to extract the characters one by one from the p1BloodType, p2BloodType, and chBloodType.

/******************************************************************************
 *
 * File name: exam_template.c
 *
 * Author:  Brian 
 *          
 *          
 *
 * Problem #: 1
 *
 * Submission Date: 14 DECEMBER 2008
 *
 ******************************************************************************/


/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 @                                                                             @
 @                              Include Files                                  @
 @                                                                             @
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include <stdio.h>

// If you need to use standard library functions other than those declared 
// in <stdio.h>, you may #include the corresponding header files here.




typedef struct ParentParentChild
{
	char p1BloodType[50];	// parent 1 blood type
	char p2BloodType[50];	// parent 2 blood type
	char chdBloodType[50];	// child blood type
} PARENTPARENTCHILD;

PARENTPARENTCHILD ParentParentChild_Table[16] =
{
{"A", "A", "{A,O}"},
{"A", "B", "{A, B, O, AB}"},
{"A", "O", "{A, O}"},
{"A", "AB", "{A, B, AB}"},
{"B", "A", "{A, B, O, AB}"},
{"B", "B", "{B, O}"},
{"B", "O", "{B, O}"},
{"B", "AB", "{A, B, AB}"},
{"O", "A", "{A, O}"},
{"O", "B", "{B, O}"},
{"O", "O", "O"},
{"O", "AB", "{A, B}"},
{"AB", "A", "{A, B, AB}"},
{"AB", "B", "{A, B, AB}"},
{"AB", "O", "{A, B}"},
{"AB", "AB", "{A, B, AB}"},
};

typedef struct ParentChildParent
{
		char p1BloodType[50];	// parent 1 blood type
		char chdBloodType[50];	// child blood type
		char p2BloodType[50];	// parent 2 blood type
} PARENTCHILDPARENT;

PARENTCHILDPARENT ParentChildParent_Table[16] =
{
{"A", "A", "{A, B, O, AB}"},
{"A", "B", "{B, AB}"},
{"A", "O", "{A, B, O}"},
{"A", "AB", "{B, AB}"},
{"B", "A", "{A, AB}"},
{"B", "B", "{A, B, O, AB}"},
{"B", "O", "{A, B, O}"},
{"B", "AB", "{A, AB}"},
{"O", "A", "{A, AB}"},
{"O", "B", "{B, AB}"},
{"O", "O", "{A, B, O}"},
{"O", "AB", "IMPOSSIBLE"},
{"AB", "A", "{A, B, O, AB}"},
{"AB", "B", "{A, B, O, AB}"},
{"AB", "O", "IMPOSSIBLE"},
{"AB", "AB", "{A, B, AB}"},
};


/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 @                                                                             @
 @                 Symbolic Constants and Type Definitions                     @
 @                                                                             @
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

// If you need to define symbolic constants or if you would like to define 
// new types, you may put the corresponding #defines and typedefs here.



/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 @                                                                             @
 @                           Global Variables                                  @
 @                                                                             @
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

// If you would like to use global variables, declare them here.




/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 @                                                                             @
 @                      Forward Function Declarations                          @
 @                                                                             @
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

// Put forward declarations of all the functions (other than main) here.




/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
 The main function: describe what your program does here.
 
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

int main(int argc, const char *argv[]) 
{
	char p1BloodType[10], p2BloodType[10], chBloodType[11];
	
	FILE *sourcefile;
	sourcefile = fopen("/users/ble1290/documents/problem 1/bloodtype.dat", "r");
	{	
		fscanf(sourcefile, "%s%s%s", &p1BloodType, &p2BloodType, &chBloodType);
		printf("%s \t", &p1BloodType);
		printf("%s \t", &p2BloodType);
		printf("%s \n", &chBloodType);

		getchar()
	}

	
	    fclose(sourcefile);

	return 0;
}



/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 @                                                                             @
 @                            Function Definitions                             @
 @                                                                             @
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

// Define (implement) all the functions here; document each function.







/******************************************************************************
 
 End of file
 
 ******************************************************************************/

PLEASE HELP! THANK YOU!!

Since p1BloodType, p2BloodType and chBloodType are character arrays you can extract characters from them using the index position of the array. So for e.g. if you want to get the character at the 10th position of the p1BloodType array what you can do is : char ch = p1BloodType[9]; // array index starts at position 0 in the same manner to read an entire array you should use a for loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.