Hello there,
Nice to be here with you on this Forum. I need your help to solve the issue with my source C code below. It worked fine before on Ubuntu 14.04, the problem appears when I upgraded my comp with the latest Ubuntu 18.04 LTS. It's a string separator : A file named "Fac.txt" is opened and will be readed line by line, then two files named "Date.txt" and "Turn.txt" should be created which contain : 1st, the date ; 2nd, the last string behind the date. I really don't know what is matter but on my first comp I had a 32 bit cpu and on the second one it's a 64 bit cpu. My compiler is Gcc 7. Thank you for your understanding.
Regards.
Hervé.
The source Code:
main.c
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define INPUT "Fac.txt"
#define DATE "Date.txt"
#define TURN "Turn.txt"
#define LONG 128
int main()
{
FILE *f_in, *fa_out, *fb_out;
char line[LONG];
char date[6];
char turn[20];
int i,j,k,l;
if ((f_in = fopen(INPUT,"r")) == NULL)
{
fprintf(stderr, "\nErr Can't open file %s\n",INPUT);
return(EXIT_FAILURE);
}
if ((fa_out = fopen(DATE,"w")) == NULL)
{
fprintf(stderr, "\nErr Can't write on file %s\n",DATE);
return(EXIT_FAILURE);
}
if ((fb_out = fopen(TURN,"w")) == NULL)
{
fprintf(stderr, "\nErr Can't write on file %s\n",TURN);
return(EXIT_FAILURE);
}
while (fgets(line,LONG,f_in) != NULL)
{
k=0;
l=0;
for(i=0;line[i]!='\n';i++)
{
j=0;
if(isdigit(line[i]) && line[i+2]==47 && line[i+5]==59)
{
for(j=i;j<=5;j++)
{
date[k]=line[j];
k++;
}
for(j=0;j<5;j++)
fprintf(fa_out,"%c", date[j]);
fprintf(fa_out,"\n");
for(j=i+7;line[j]!='\n';j++)
{
if(line[j]!=34)
turn[l++]=line[j];
}
fprintf(fb_out," ");
for(j=0;j<l;j++)
fprintf(fb_out,"%c", turn[j]);
fprintf(fb_out,"\n");
}
}
}
fclose(fa_out);
fclose(fb_out);
return(EXIT_SUCCESS);
}
- an example of Fac.txt
02/08; ELIS TRAPPES; 78190 TRAPPES 02/08; ELIS ST THIBAULT; 77400 ST THIBAULT DES VIGNES
01/08; ELIS ST THIBAULT; 77400 ST THIBAULT DES VIGNES 01/08; ELIS / TRAPPES; 78190 TRAPPES
01/08; CCF; 92000 NANTERRE 01/08; ; 92130 ISSY LES MOULINEAUX
01/08; KONICA CONSOMMABLES; 78420 CARRIERES SUR SEINE 01/08; ; 93600 AULNAY SOUS BOIS
02/08; CCF; 92000 NANTERRE 02/08; ; 94130 NOGENT SUR MARNE
02/08; RESO COLLEGIEN; 77090 COLLEGIEN 02/08; ; 93600 AULNAY SOUS BOIS