#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <conio.h>
#include <windows.h>
int TotalCI = 0;
int count = 0;
struct depend{
char dependency[200];
};
struct intdepend{
char interdependency[200];
};
struct infradep{
char name[200];
int depcount;
struct depend Dep[20];
int intdepcount;
struct intdepend IntDep[20];
};
struct infradep ci[50];
void menuModel(){
int menu4;
system("cls");
printf("=========================================\n");
printf("\tDependency Model\n");
printf("=========================================\n");
count = 0;
for (int j=0; j < TotalCI; j++)
{
count++;
// printf("%d)",count);
// printf("%s\n",ci[j].name);
for(int k=0; k <= ci[j].depcount; k++)
{
if(ci[j].Dep[k].dependency != 0)
{
printf(" %s ---> %s\n", ci[j].name, ci[j].Dep[k].dependency);
}
}
for(int m=0; m <= ci[j].intdepcount; m++)
{
if(ci[j].IntDep[m].interdependency != 0)
{
printf(" %s <---> %s\n", ci[j].name, ci[j].IntDep[m].interdependency);
}
}
}
}
Im trying to print out the non null value from my struc Dep[20] and struct IntDep[20]. The IF statement works but, it displays like this:
=========================================
Dependency Model
=========================================
Drinking Water ---> Food
Drinking Water ---> Transport
Drinking Water --->
Drinking Water <---> Food
Drinking Water <--->
Waste Water ---> Chemical
Waste Water ---> Manufacture
Waste Water --->
Waste Water <--->
The code print extra line with null struct value, making it look weird. Can anyone teach me or help me how to fix this?
for(int k=0; k <= ci[j].depcount; k++)You may want<instead of<=here.dependencyis a string, not a pointer. It can never be null.ifstatement works?