Hi all, noob here. I’m trying to run a program in Dev-C++ that was created in Turbo C++. I already changed a few things, like updating the header files and replacing clrscr() with fflush, but it gives me a runtime error which causes the program to close (although the program is along, so I won’t post all of it here). There are also several compile errors, which I placed in comments on the line where they appear in the code:
Does anyone know how to fix these? Here is the code for the function containing the errors:
Hope this isn’t too ugly...sorry it's so long. This is my first time posting here, and I tried not to appear as a big artard. Thanks!Code:void insertCar(){ int valid1, valid2, valid3, valid; char carArray[MAX_LENGTH]={'\0'}; char *honda = "honda", *ford = "ford", *mercedes = "mercedes", *toyota = "toyota"; int i,p=0; //[Warning] matches this `i' under ISO standard rules int k; //[Warning] matches this `k' under ISO standard rules int numDigits; int indexOfFirstDigit=0; int yearAsInt; char *make; do{ valid = 1; valid1 = 1; valid2 = 1; valid3 = 1; char *year; make = '\0'; yearAsInt=0; numDigits=0; i=0; cout <<"\nEnter car information: "; fflush(stdin); gets(carArray); fflush(stdin); while (i<MAX_LENGTH){ if (isdigit(carArray[i])) numDigits++; i++; } if (numDigits == YEAR_SHORT || numDigits == YEAR_LONG){ i=0; while (i<MAX_LENGTH){ if (isdigit(carArray[i])){ indexOfFirstDigit=i; break; } i++; } strncpy(year, carArray+indexOfFirstDigit, numDigits); yearAsInt = atoi(year); if(indexOfFirstDigit>0) { strncpy(make, carArray, indexOfFirstDigit-1); int f = 0; for(int j = 0; j < strlen(make); j++) if(make[j] == ':') { f = 1; make[j] = '\0'; break; } if(f==0) { cout<<"colon is missing"<<endl; insertCar(); } } else{ i=0; while(carArray[i]!='\0'){ p++; i++; } p = p-numDigits; strncpy(make, carArray+numDigits+1,p); } for(int i = 0; i < strlen(make); i++) //[Warning] matches this `i' under old rules if(make[i]>=65 && make[i]<=90) make[i] = make[i] + 32; int f = 0; for(i = 0; i < strlen(honda); i++) //[Warning] name lookup of `i' changed { if(make[i] != honda[i]) { f = 0; break; } else f = 1; } if(f==0) for(i = 0; i < strlen(ford); i++) { if(make[i] != ford[i]) { f = 0; break; } else f = 1; } if(f==0) for(i = 0; i < strlen(toyota); i++) { if(make[i] != toyota[i]) { f = 0; break; } else f = 1; } if(f==0) for(i = 0; i < strlen(mercedes); i++) { if(make[i] != mercedes[i]) { f = 0; break; } else f = 1; } if(f==1) { if (numDigits == YEAR_SHORT){ if (yearAsInt >= 75 && yearAsInt <= 99 || yearAsInt >= 0 && yearAsInt <= 2) valid1=1; else{ valid1=0; cout<<endl<<"Invalid range"; } } else{ if (yearAsInt >= 1975 && yearAsInt <= 2002) valid2=1; else{ valid2=0; cout<<endl<<"Invalid range"; } } if(numDigits == YEAR_SHORT && valid1 == 1){ if(yearAsInt >= 75 && yearAsInt <= 99) yearAsInt = yearAsInt + 1900; else if(yearAsInt >= 0 && yearAsInt <= 2) yearAsInt = yearAsInt + 2000; } } else{ cout<<" make is not in the list"<<endl; valid=0; } } else{ valid3=0; cout<<"wrong year format"<<endl; } } while(!valid || !valid1 || !valid2 || !valid3); if(x < 4) { carInfo[flag] = new char[strlen(carArray)]; makeName[flag] = new char[strlen(make)]; for(int j = 0; j < strlen(carArray); j++) carInfo[x][j] = carArray[j]; carInfo[x][strlen(carArray)] = '\0'; for(int k = 0; k < strlen(make); k++) //[Warning] matches this `k' under old rules makeName[x][k] = make[k]; makeName[x][strlen(make)] = '\0'; yearArray[x] = yearAsInt; int f = 0; if(x>0 && yearArray[x - 1] == yearArray[x]){ for(k = 0; k < strlen(make); k++){ // [Warning] name lookup of `k' changed if(makeName[x-1][k] == make[k]) f = 1; else break; } if(f == 1){ cout<<"Duplicate Entry"; insertCar(); } } flag++; x++; cout << "\n******************************\n\n"; cout << "Inserted\n\n"; cout << "******************************\n\n"; } else cout<<endl<<"Exceed the input limit"; displayMenu(); }



LinkBack URL
About LinkBacks



