ניסיון שני לצירוף קוד
void createNewBarcode(){ int destCity;
int i;
int j; int k; int m; int codeFlag=1; int oddSum; int evenSum; int checksum; int inlist=1; char newcodeInChar[13]; char tempCodeFromList[13]; char codeInUpcNumsVal[49]; FILE *newBarcode; FILE *BarcodeList; //for bitmap header char signature [2] = {'B', 'M'}; unsigned int fileSize = 29734;//NEED TO CHANGE unsigned short int reserve1=0; unsigned short int reserve2=0; unsigned int offset = 54; //for DIB header unsigned int dibheaderSize=40; unsigned int width=141; unsigned int height=70; unsigned short int planes=1; unsigned short int bbp=24; unsigned int compression=0; unsigned int imageSize=0;//NEED TO CHANGE unsigned int xppm=0; unsigned int yppm=0; unsigned int numberOfColors=0; unsigned int numberOfImpColor=0; char black=0; char white = 255; //get the destination city printf("Insert destination city:\n"); while(1){ destCity=inputCheckNumbersNoExit(9,0); if(destCity==0) printf("Destination city can not be zero.\n"); else break; } //Create random code newcodeInChar[0]=newcodeInChar[2]='2'; newcodeInChar[1]= newcodeInChar[3] = '0'; newcodeInChar[4] = destCity + 48; while(codeFlag){//we create random codes until we find one that is not already in the list //creating code for(i=5; i<11; i++){ newcodeInChar = (rand()%10) + 48;//+48, because rand gives int and we need char. 48 is the jump in asci between 0 and '0' } newcodeInChar[12]='\0'; //close the string //creating checkSum oddSum=evenSum=checksum=0; for(i=0; i<11 ; i= i+2 ) oddSum = oddSum + (newcodeInChar-48);//get even and odd sums in int oddSum = oddSum*3; for(i=1; i<10 ; i=i+2) evenSum = evenSum + (newcodeInChar-48); evenSum = evenSum + oddSum; checksum = 10 - (evenSum%10); checksum=checksum + 48;//+ 48: puts in checksum the char value of checksum newcodeInChar[11]=checksum; //now we check if the new barcode is already int the list inlist=checkIfBarcodeInList(newcodeInChar); if(inlist==0)//if barcode is in the list continue; else//we found a good code codeFlag=0; } //turn the barcode from digits to upc numbers j=0; for(i=0; i<12; i++){ switch(newcodeInChar){ case 48://'0' codeInUpcNumsVal[j] = 3; j++; codeInUpcNumsVal[j] = 2; j++; codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 1; j++; break; case 49://'1' codeInUpcNumsVal[j] = 2; j++; codeInUpcNumsVal[j] = 2; j++; codeInUpcNumsVal[j] = 2; j++; codeInUpcNumsVal[j] = 1; j++; break; case 50://'2' codeInUpcNumsVal[j] = 2; j++; codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 2; j++; codeInUpcNumsVal[j] = 2; j++; break; case 51://'3' codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 4; j++; codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 1; j++; break; case 52://'4' codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 3; j++; codeInUpcNumsVal[j] = 2; j++; break; case 53://'5' codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 2; j++; codeInUpcNumsVal[j] = 3; j++; codeInUpcNumsVal[j] = 1; j++; break; case 54://'6' codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 4; j++; break; case 55://'7' codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 3; j++; codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 2; j++; break; case 56://'8' codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 2; j++; codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 3; j++; break; case 57://'9' codeInUpcNumsVal[j] = 3; j++; codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 1; j++; codeInUpcNumsVal[j] = 2; j++; break; } } codeInUpcNumsVal[j]='\0'; //CREATE BARCODE HEADERS if(!(newBarcode = fopen("newbarcodeself.bmp","wb"))){ printf("Problem with opening new file.\n"); return; } //bitmap header fwrite(&signature, 1, 2, newBarcode); fwrite(&fileSize, 4, 1, newBarcode); fwrite(&reserve1, 2, 1, newBarcode); fwrite(&reserve2, 2, 1, newBarcode); fwrite(&offset, 4, 1, newBarcode); //DIB header fwrite(&dibheaderSize, 4, 1, newBarcode); fwrite(&width, 4, 1, newBarcode); fwrite(&height, 4, 1, newBarcode); fwrite(&planes, 2, 1, newBarcode); fwrite(&bbp, 2, 1, newBarcode); fwrite(&compression, 4, 1, newBarcode); fwrite(&imageSize, 4, 1, newBarcode); fwrite(&xppm, 4, 1, newBarcode); fwrite(&yppm, 4, 1, newBarcode); fwrite(&numberOfColors, 4, 1, newBarcode); fwrite(&numberOfImpColor, 4, 1, newBarcode); //writing white part at top for(i=0; i<11; i++){ for(j=0; j<423 ; j++) fwrite(&white, 1, 1, newBarcode); fwrite(&black, 1, 1, newBarcode); } //writing the longer lines (same for every code) for(i=0; i<4 ; i++){ for (j=0; j<63; j++)//white from th left fwrite(&white, 1, 1, newBarcode); //left lines for(j=0; j<3; j++) fwrite(&black, 1, 1, newBarcode); for(j=0; j<3; j++) fwrite(&white, 1, 1, newBarcode); for(j=0; j<3; j++) fwrite(&black, 1, 1, newBarcode); for(j=0 ; j<129; j++)//between left and middle lines fwrite(&white, 1, 1, newBarcode); //middle lines for(j=0; j<3; j++) fwrite(&black, 1, 1, newBarcode); for(j=0; j<3; j++) fwrite(&white, 1, 1, newBarcode); for(j=0; j<3; j++) fwrite(&black, 1, 1, newBarcode); for(j=0 ; j<129; j++)//between middle and right lines fwrite(&white, 1, 1, newBarcode); //right lines for(j=0; j<3; j++) fwrite(&black, 1, 1, newBarcode); for(j=0; j<3; j++) fwrite(&white, 1, 1, newBarcode); for(j=0; j<3; j++) fwrite(&black, 1, 1, newBarcode); for (j=0; j<75 ; j++) fwrite(&white, 1, 1, newBarcode); fwrite(&black, 1, 1, newBarcode);//end of line } //PRINTING CODE for(i=0; i<45 ; i++){//printing 45 lines of barcode for(j=0; j<63 ; j++) fwrite(&white, 1, 1, newBarcode);//white from left //three left lines for(j=0; j<3; j++) fwrite(&black, 1, 1, newBarcode); for(j=0; j<3; j++) fwrite(&white, 1, 1, newBarcode); for(j=0; j<3; j++) fwrite(&black, 1, 1, newBarcode); //printing 6 first code digits (on cells 0-23 on codeInUpcNumsVal) for(k=0 ; k<23 ; k++){ for(m=0 ; m < (codeInUpcNumsVal[k]*3) ; m++){//*3 so it would print 3*value (3 notes for every digit) //the left helf - print white for even place, black