zeros.c
Code:
#include <stdio.h>
#include <string.h>
#define FILE_SIZE_MAX 10000
#define NUMBER_SIZE_MAX 10
#define FILE_IMPORT "acct.txt"
#define FILE_EXPORT "acctnew.txt"
char importData[FILE_SIZE_MAX];
char exportData[FILE_SIZE_MAX];
char tmpData[NUMBER_SIZE_MAX];
char tmp[NUMBER_SIZE_MAX];
void import() {
memset(importData,0,sizeof(importData));
memset(tmpData,0,sizeof(tmpData));
FILE* file = fopen(FILE_IMPORT, "r");
while (fgets(tmpData, sizeof(tmpData), file)) {
strcat(importData, tmpData);
};
fclose(file);
};
char *fixNumber() {
memset(tmp,0,sizeof(tmp));
int addZeros = 5 - strlen(tmpData);
for (int i = 0; i < addZeros; i++) {
strcat(tmp,"0");
};
strcat(tmp,tmpData);
memset(tmpData,0,sizeof(tmpData));
return tmp;
};
int main(int argc, char *argv[]) {
tmpData[0] = '\0';
import(); int i; int count = 0;
remove(FILE_EXPORT);
FILE *exportFile = fopen(FILE_EXPORT, "a");
for (i = 0; i < strlen(importData); i++ ) {
if (importData[i] == '\n') {
if (count <= 4 && count != 0) {
fprintf(exportFile, "%s\n", fixNumber());
} else {
fprintf(exportFile, "%s\n", tmpData);
};
count = 0;
} else {
tmpData[count] = importData[i];
count++;
};
};
fclose(exportFile);
};
It is flawed and i threw it together really quick but i'm assuming it will help you on the way to a final product.