Hi Everyone,
As a continuation of one of my previous questions...URL below
alphanumeric increment in C[
^]
Using the above working code, I open a file, use fgets and sscanf to scan the rows. Each row has a number of items, one of which is a value of 6 characters. The code then "renumbers" it down to 4 characters and prints it out to an output file. What I need to do now is the following:
1. open another, different file, call it FILE2, that also contains the same the 6 character values in a different layout
2. I need to scan FILE2, until I find the one of the 6 character values
3. Then I need to go to the FILE1, find the same 6 Character value and find and store it's matching 4 character value
4. Go back to FILE2 replace the 6 character value it with it's equivalent 4 character value.
Original code snippit is below:
#include <stdAfx.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include "CProgtest.h"
int main()
{
char *pdest;
char t0[50] = "**";
char t1[50] = "COOR";
char lnLabel[50], lLabel[50], nLabel[50], line[200];
long i, j, k, l10, l20, l30, l40, l50, l60, l70, l80, l90;
long n10[2000], n20[2000], n30[2000], n40[2000], n50[2000], n60[2000];
long n70[2000], n80[2000], n90[2000];
long NodeName;
double xA, xB, yA, yB, zA, zB;
double x, y, z;
Operations P;
for (k = 0; k < 2000; k++)
{
n10[k] = 0; n20[k] = 0; n30[k] = 0; n40[k] = 0; n50[k] = 0; n60[k] = 0; n70[k] = 0; n80[k] = 0; n90[k] = 0;
}
l10 = 10; l20 = 20; l30 = 30; l40 = 40; l50 = 50; l60 = 60; l70 = 70; l80 = 80; l90 = 90;
FILE *pFile, *sacsout;
pFile = fopen("ASASIN.txt", "r");
if( (sacsout = fopen("Sacs1.inp", "w" )) != NULL )
{
}
else
{printf( "Problem creating SACS Output file\n");}
while(fgets(line, sizeof line, pFile) != NULL)
{
if(sscanf_s(line, "%d %lf %lf %lf", &NodeName, &x, &y, &z) == 4)
fprintf(sacsout,"JOINT ");
{
j = NodeName / 10000;
if(j < 20 )
{
if (j != l10 )
{
l10 = j;
}
n10[l10] += 1;
fprintf(sacsout,"%2d", l10);
fprintf(sacsout,"%02lX", n10[l10]);
sprintf(lLabel,"%d", l10);
sprintf(nLabel, "%02lX", n10[l10]);
strcpy(lnLabel, lLabel);
strcat(lnLabel, nLabel);
goto skp;
}
if(j < 30)
{
if( j != l20)
{
l20 = j;
}
n20[l20] += 1;
fprintf(sacsout,"%2d", l20);
fprintf(sacsout,"%02lX", n20[l20]);
sprintf(lLabel,"%d", l20);
sprintf(nLabel, "%02lX", n20[l20]);
strcpy(lnLabel, lLabel);
strcat(lnLabel, nLabel);
goto skp;
}
if(j < 40)
{
if( j != l30)
{
l30 = j;
}
n30[l30] += 1;
fprintf(sacsout,"%2d", l30);
fprintf(sacsout,"%02lX", n30[l30]);
sprintf(lLabel,"%d", l30);
sprintf(nLabel, "%02lX", n30[l30]);
strcpy(lnLabel, lLabel);
strcat(lnLabel, nLabel);
goto skp;
}
if(j < 50)
{
if( j != l40)
{
l40 = j;
}
n40[l40] += 1;
fprintf(sacsout,"%2d", l40);
fprintf(sacsout,"%02lX", n40[l40]);
sprintf(lLabel,"%d", l40);
sprintf(nLabel, "%02lX", n40[l40]);
strcpy(lnLabel, lLabel);
strcat(lnLabel, nLabel);
goto skp;
}
if(j < 60)
{
if( j != l50)
{
l50 = j;
}
n50[l50] += 1;
fprintf(sacsout,"%2d", l50);
fprintf(sacsout,"%02lX", n50[l50]);
sprintf(lLabel,"%d", l50);
sprintf(nLabel, "%02lX", n50[l50]);
strcpy(lnLabel, lLabel);
strcat(lnLabel, nLabel);
goto skp;
}
if(j < 70)
{
if( j != l60)
{
l60 = j;
}
n60[l60] += 1;
fprintf(sacsout,"%2d", l60);
fprintf(sacsout,"%02lX", n60[l60]);
sprintf(lLabel,"%d", l60);
sprintf(nLabel, "%02lX", n60[l60]);
strcpy(lnLabel, lLabel);
strcat(lnLabel, nLabel);
goto skp;
}
if(j < 80 )
{
if (j != l70 )
{
l70 = j;
}
n70[l70] += 1;
fprintf(sacsout,"%2d", l70);
fprintf(sacsout,"%02lX", n70[l70]);
sprintf(lLabel,"%d", l70);
sprintf(nLabel, "%02lX", n70[l70]);
strcpy(lnLabel, lLabel);
strcat(lnLabel, nLabel);
goto skp;
}
if(j < 90 )
{
if (j != l80 )
{
l80 = j;
}
n80[l80] += 1;
fprintf(sacsout,"%2d", l80);
fprintf(sacsout,"%02lX", n80[l80]);
sprintf(lLabel,"%d", l80);
sprintf(nLabel, "%02lX", n80[l80]);
strcpy(lnLabel, lLabel);
strcat(lnLabel, nLabel);
goto skp;
}
if(j < 100 )
{
if (j != l90 )
{
l90 = j;
}
n90[l90] += 1;
fprintf(sacsout,"%2d", l90);
fprintf(sacsout,"%02lX", n90[l90]);
sprintf(lLabel,"%d", l90);
sprintf(nLabel, "%02lX", n90[l90]);
strcpy(lnLabel, lLabel);
strcat(lnLabel, nLabel);
goto skp;
}
skp:;
}