Dude, review your posts before pressing submit!
Your code looks worse and worse every time you post it.
Turn OFF tabs in your editor, and make it use 2 or 4 spaces
Example code indented with tabs. Observe how the board blows tabs up out of all proportion.
Code:
void foo(int a[][10][20], int max)
{
int x, y, z;
for (x = 0; x < max; x++) {
for (y = 0; y < 10; y++) {
for (z = 0; z < 20; x++) {
a[x][y][z] = 0;
}
}
}
}
Same example code indented with spaces
Code:
void foo ( int a[][10][20], int max ) {
int x, y, z;
for ( x = 0 ; x < max ; x++ ) {
for ( y = 0 ; y < 10 ; y++ ) {
for ( z = 0 ; z < 20 ; x++ ) {
a[x][y][z] = 0;
}
}
}
}
Now, here's your code
Code:
#include<stdio.h>
#include<stdlib.h>
struct switch_matrix {
int pin_no;
int line_used;
struct switch_matrix *nextptr;
};
struct switch_block {
struct switch_matrix *Array[40];
} Layout[18][18];
typedef struct switch_matrix SWITCH;
void build_univ_switch(struct switch_block *X);
void fill_list(int a1, int a2, int b1, int b2, int t1, int t2);
void file_read(FILE * file_pointer);
int main()
{
FILE *fp;
fp = fopen("e64.r", "r");
file_read(fp);
fclose(fp);
return (0);
}
void file_read(FILE * file_pointer)
{
int x1 = 0, x2 = 0, y1 = 0, y2 = 0, trackno1 = 0, trackno2 = 0, m, n;
char ch;
while (!feof(file_pointer)) {
fill_list(x1, x2, y1, y2, trackno1, trackno2);
ch = fgetc(file_pointer);
if (ch == 'S') {
x1 = 0;
y1 = 0;
x2 = 0;
y2 = 0;
ch = fgetc(file_pointer);
if (ch == 'C') {
ch = fgetc(file_pointer);
if (ch == 'H') {
ch = fgetc(file_pointer);
if (ch == 'A') {
ch = fgetc(file_pointer);
if (ch == 'N') {
ch = fgetc(file_pointer);
if (ch == 'X') {
ch = fgetc(file_pointer); //the blank
ch = fgetc(file_pointer); //the (
fscanf(file_pointer, "%d", &x1);
printf("%d\n", x1);
ch = fgetc(file_pointer); //the ,
fscanf(file_pointer, "%d", &y1);
printf("%d\n", y1);
for (m = 0; m < 10; m++) //no of charac till u reach track no
ch = fgetc(file_pointer);
fscanf(file_pointer, "%d", &trackno1);
printf("go\n");
printf("%d\n", trackno1);
} else if (ch == 'Y') {
ch = fgetc(file_pointer); //the blank
ch = fgetc(file_pointer); //the (
fscanf(file_pointer, "%d", &x2);
printf("%d\n", x2);
ch = fgetc(file_pointer); //the ,
fscanf(file_pointer, "%d", &y2);
printf("%d\n", y2);
for (n = 0; n < 10; n++) //no of charac till u reach track no
ch = fgetc(file_pointer);
fscanf(file_pointer, "%d", &trackno2);
printf("%d\n", trackno2);
}
}
}
}
}
}
}
}
void build_univ_switch(struct switch_block *X)
{
SWITCH *head;
SWITCH *currentptr;
int i, j;
for (i = 0; i < 40; i++) {
/*BUILDS LINKED LIST */
head = NULL;
for (j = 1; j <= 4; j++) {
currentptr = (SWITCH *) malloc(sizeof(SWITCH));
currentptr->line_used = 0;
currentptr->nextptr = head;
head = currentptr;
}
X->Array[i] = head;
}
}
void fill_list(int a1, int a2, int b1, int b2, int t1, int t2)
{
SWITCH *temp;
if (a1 == a2 && a1 != 0) {
if (b1 == b2 && b1 != 0) {
temp = Layout[17 - b1][a1].Array[19 + t2];
temp = temp->nextptr;
temp->line_used = 1;
temp = Layout[17 - b1][a1].Array[19 - t1];
temp = temp->nextptr;
temp = temp->nextptr;
temp->line_used = 1;
}
else {
if (b2 == b1 + 1) {
temp = Layout[17 - b1][a1].Array[19 - t1];
temp->line_used = 1;
temp = Layout[17 - b1][a1].Array[9 - t2];
temp = temp->nextptr;
temp->line_used = 1;
} else {
if (b2 > b1 + 1) {
temp = Layout[17 - (b2 - 1)][a1].Array[19 + t2];
temp->line_used = 1;
temp = Layout[17 - (b2 - 1)][a1].Array[9 - t2];
temp = temp->nextptr;
temp = temp->nextptr;
temp->line_used = 1;
}
}
}
} else {
if (b1 == b2) {
if (a1 == a2 + 1) {
temp = Layout[17 - b2][a2].Array[19 + t2];
temp = temp->nextptr;
temp = temp->nextptr;
temp = temp->nextptr;
temp->line_used = 1;
temp = Layout[17 - b2][a2].Array[29 + t1];
temp = temp->nextptr;
temp = temp->nextptr;
temp->line_used = 1;
} else {
if (a1 > a2 + 1) {
temp = Layout[17 - a1][a1 - 1].Array[19 - t1];
temp = temp->nextptr;
temp = temp->nextptr;
temp = temp->nextptr;
temp->line_used = 1;
temp = Layout[17 - b1][a1 - 1].Array[29 + t1];
temp = temp->nextptr;
temp->line_used = 1;
}
}
} else {
if (b2 == b1 + 1) {
temp = Layout[17 - b1][a2].Array[9 - t2];
temp = temp->nextptr;
temp = temp->nextptr;
temp = temp->nextptr;
temp->line_used = 1;
temp = Layout[17 - b1][a2].Array[29 + t1];
temp->line_used = 1;
}
}
}
}
Now, lets deal with file_read first, and make sure it is extracting all the data you want, and rejecting all the data you don't want. Then we can work on calling your other functions in another post.
> while (!feof(file_pointer))
Read the FAQ.
We can simplify this function and avoid a lot of different ways of reading the file fgetc, fscanf etc.
Code:
char buff[BUFSIZ];
while ( fgets( buff, BUFSIZ, file_pointer ) != NULL ) {
if ( strncmp( buff, "SCHAN", 5 ) == 0 ) {
/* now compare buff[6] to see if it's 'X' or 'Y' */
}
}
Then you can do something like this to extract data from the interior of the buffer
Code:
sscanf( &buff[7], "%d %d", &x, &y );
Posting a couple of examples of SCHANX and SCHANY lines would really help.