Hi Everyone,
Following on from a previous thread... I have been given code that I need to convert to be able to read in a program. One of the main problems is that the primary field I have to convert has 6 characters and I need to convert it to 4 characters, obviously unique. The 6 characters are divided into groups of 2, each group means something, however the first group is the one with the most useful informaton.
Example:
102030
10 is the useful field
20 is just descriptive
30 is just descriptive
Some examples are:
107011
151030
151070
152930
152970
171030
171070
141030
111030
111070
201030
201070
To convert the above to 4 characters instead of 6 I have devised a plan to keep the first 2 characters, but increment the 2nd two until it hits a new number.
Eg:
107011
151030 will be 151
151070 will be 152
152930 will be 153
152970 will be 154
171030 will be 171
The problem I have is that some of them have more than 99 items. Using the above examples and assuming I have 99 number 15's, the last one will be 1599 and the one after will be 15100..which is 5 characters. I therefore thought I could come up with an alphanumeric option. Eg: 15A1, 15A2....15A9, 15B1....15B9, 15C1...15C9, etc. This means I can go up to 26 * 9 = 234 items per number. My problems is...I have no idea how to do it. My current code snippet is as follows:
#include <stdAfx.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int main()
{
char line[200];
long i, j, k, n10, n20, n30, n40, n50, n60, l10, l20, l30, l40, l50, l60;
long NodeName;
double x, y, z;
n10 = 0; n20 = 0; n30 = 0; n40 = 0; n50 = 0; n60 = 0;
l10 = 10; l20 = 20; l30 = 30; l40 = 40; l50 = 50; l60 = 60;
FILE *pFile, *OutPut;
pFile = fopen("Input.txt", "r");
if( (OutPut = fopen("Output.inp", "w" )) != NULL )
{
}
else
{printf( "Problem creating Output file\n");}
while(fgets(line, sizeof line, pFile) != NULL)
{
if(sscanf_s(line, "%d %lf %lf %lf", &NodeName, &x, &y, &z) == 4)
{
j = NodeName / 10000;
if(j < 20 )
{
if( j > l10)
{
l10 = j;
n10 = 0;
}
n10 += 1;
fprintf(OutPut,"%2d", l10);
fprintf(OutPut,"%2d ", n10);
goto skp;
}
if(j < 30)
{
if( j > l20)
{
l20 = j;
n20 = 0;
}
n20 += 1;
fprintf(OutPut,"20");
fprintf(OutPut,"%2d ", n20);
goto skp;
}
if(j < 40)
{
if( j > l30)
{
l30 = j;
n30 = 0;
}
n30 += 1;
fprintf(OutPut,"30");
fprintf(OutPut,"%2d ", n30);
goto skp;
}
if(j < 50)
{
if( j > l40)
{
l40 = j;
n40 = 0;
}
n40 += 1;
fprintf(OutPut,"40");
fprintf(OutPut,"%2d ", n40);
goto skp;
}
skp:;