Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- /*
- * PRODUCT.TXT
- * {IDFABRICANTE[3]} {CODPRODUCTO[4]} {AÑO[4]}
- *
- * BARRANUM.TXT
- * {CODIGO}
- */
- void menu();
- void codigo_barras();
- void menor_cantidad();
- void buscar_productos(int empresa);
- int generar_digito(int buffer[8]);
- int generar_codigo();
- char opt;
- int main(){
- /* do{
- menu();
- } while(opt != 'C');
- */
- //printf("%d",generar_codigo());
- buscar_productos(11);
- return 0;
- }
- void menu(){
- printf("\n A - CÓDIGO DE BARRAS \n B - MENOR CANTIDAD SOLICITADA \n C - FIN");
- scanf("%c",&opt);
- switch(opt){
- case 'A':
- codigo_barras();
- break;
- case 'B':
- menor_cantidad();
- break;
- }
- }
- void codigo_barras(){
- int empresa;
- printf("Ingrese Empresa: ");
- scanf("%d", &empresa);
- printf("\n");
- }
- int generar_codigo(){
- int buffer[8],digito,i,k,b,empresa[3],producto[4];
- empresa[0] = 3;
- empresa[1] = 1;
- empresa[2] = 2;
- producto[0] = 1;
- producto[1] = 1;
- producto[2] = 2;
- producto[3] = 4;
- k=2;
- for(i=0;i<=2;i++){
- buffer[i] = empresa[i];
- k--;
- }
- k=0;
- for(i=3;i<=6;i++){
- buffer[i] = producto[k];
- k++;
- }
- buffer[7] = generar_digito(buffer);
- b=0;
- k=0;
- for(i=7;i>=0;i--){
- b += buffer[k]*pow(10,i);
- k++;
- }
- return b;
- }
- int generar_digito(int buffer[8]){
- int impar = 0;
- int par = 0;
- int b,i;
- for(i=0;i<=6;i++){
- if(i%2 == 0)
- impar += buffer[i];
- else
- par += buffer[i];
- }
- b = (3*impar)+par;
- if(b % 10 == 0)
- return 0;
- else
- return 10 - (int)(b%10);
- }
- void menor_cantidad(){
- }
- void buscar_productos(int empresa){
- FILE *fh;
- int ch,buffer[3],k;
- fh=fopen("PRODUCT.TXT","r");
- if(fh==NULL) {
- puts("Can't open that file!");
- exit(1);
- }
- k=2;
- buffer = 0;
- while((ch=fgetc(fh))!=EOF){
- buffer += ch*pow(10,k);
- if(k <= 0)
- k--;
- } else{
- if(ch == '\0')
- k=2;
- }
- putchar(ch);
- }
- fclose(fh);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement