/* buggy1.c, created April 24, 1999, last modified April 24, 1999, */ /* by Rick Wagner. Copyright 1999, all rights reserved. */ /* */ /* Created for use in USC's csci 101. */ /* */ /* This program file will compile and run but won't get the desired */ /* result. Debug it. */ #include typedef struct { int iNumIntegers; /* The number of integers in the array. */ int iArray[100]; /* Array to store integers. */ } IntegerVector; /* Function prototypes: */ int searchVector(IntegerVector iv, int iSearchFor); void main() { int i = 0; int iLookFor = 13; int iFoundFlag = 0; IntegerVector ivA; ivA.iNumIntegers = 7; for (i = 0; i < ivA.iNumIntegers; i++) { ivA.iArray[i] = i; /* Ssequential integers. */ } /* Search for iLookFor: */ iFoundFlag = searchVector(ivA, iLookFor); if (iFoundFlag) { printf("I found the integer %d in the array.\n", iLookFor); } else { printf("I did not find the integer %d in the array.\n", iLookFor); } } int searchVector(IntegerVector iv, int iSearchFor) { int iResult = 0; /* Default result is FALSE */ int i = 0; for (i = 0; i < iv.iNumIntegers; i++) { if (iv.iArray[i] = iSearchFor) { iResult = 1; /* Set the result to TRUE */ break; /* Break out of the for() */ } } return iResult; }