It should look something like this:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *ifp, *ofp; /* input file pointer,output file pointer */
ifp = fopen("c:\\test1.txt", "r"); /* open for reading */
ofp = fopen("c:\\test2.txt", "w"); /* open for writing */
double read_num;// the number being read from the file
double d1[1000];// array to store numbers
double d2[1000];// array to stor numbers, do note that d1[i] and d2[i] are connected to
// each other via bridge
double no_of_rooms = 0; // no of rooms
double no-of_tunnels = 0; // no of bridges
int count = 0; // count how many bridges to crush that connect 1 to 0 directly.
int count2 = 0; // count bridges connected at some room
int e = 0;// used to store all rooms in the array..
if(fscanf (ifp,"%lf",&read_num ) == 1 )
{
no_of_rooms = read_num;// c is number of rooms
}
if(fscanf (ifp,"%lf",&read_num) == 1 )
{
no-of_tunnels = read_num;// q is number of tunnels
}
// store each connected rooms by a tunnel in an array
while(fscanf (ifp,"%lf",&read_num ) == 1 && e < no-of_tunnels )
{
// note here. if rooma 1 and 2 are connected. d1[e] stores 1 and d2[e] stores 2
int qw = (int)read_num;
fscanf (ifp,"%lf",&read_num);
int z = (int)read_num;
d1[e] = qw;
d2[e] = z;
e++;
}
int i2 = 1;// used to check until no_of_rooma..from room = i2 = 1 to room c
int i1;// used to check from bridges i1 to q. then is restored to 0..to check for bridges for
// next room
int final_answer = 0;// last number needed, the final answer of how much bridges to crush
int yu = 0;// needed to initialize bridges to crush at room 1.
while(i2<no_of_rooms )
{
i1 = 0;
while(i1< no-of_tunnels )
{
// check if room 1 has a way out directly. if so, crash that tunnel
if(d1[i1] == 1 && d2[i1] == 0)
count++;
// check if room 1 has a way out directly. if so, crash that tunnel
if(d1[i1] == 1 && d2[i1] == 0)
count++;
// for each room check how much tunnels need to be broken
if(d1[i1] == 1 && d2[i1] != 0 && i2 == 1)
count2++;
if(d2[i1] == 1 && d1[i1] != 0 && i2 == 1)
count2++;
if(d1[i1] == i2 && d1[i1] != 1)
count2++;
if(d2[i1] == i2 && d2[i1] != 1)
count2++;
i1++;
}
// o at first is how much bridges we cut at 1. then if there is way to crush much less we crash at that
// point.
if((o >= count2 || yu == 0))
{
final_answer = count2;
yu++;
}
count2 = 0;
i2++;
}
count += final_answer;
printf(" ");
printf(" ");
printf("%d",final_answer);
fclose(ifp);
fclose(ofp);
return 0;
}
It's called indentation.