Hi all,
I need ur help..
Actually I have to read the data file which containing character and digits. I need to converts some characters into digit.
The data file is like:
A11111
B22222
B33333
B4444
A55555B66666
B77777
So far my programming is like this:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#define EOL '\n'
#define N 100
void OpenFile(void);
void ReadFile(void);
void ConvData(void);
char data[N];
FILE *dataptr;
unsigned int i,ii;
char *data2=malloc(strlen(data));
long k;
main()
{
clrscr();
OpenFile();
if (dataptr!=0)
{
ReadFile();
printf("read\n");
fclose(dataptr); }
{
ConvData(); }
return 0;
}
void OpenFile(void)
{
dataptr=fopen("data.dat","r");
if (dataptr==0){
printf("ERROR - Cannot open the file\n");
}
return;
}
void ReadFile(void)
{
printf("DATA FILE:\n");
while (!feof(dataptr))
{
printf("%-40s",data);
fscanf(dataptr,"%s",data);
}
}
void ConvData(void)
{ dataptr=fopen("data.dat","r");
for(i=0;i<=6;i++){
fscanf(fptdrill,"%s",data);
printf("\ndata[%i]=%s",i,data);
}
if (data2!=NULL){
memset(data2, 0, sizeof data);
{ for (ii = 0, i = 0; i < strlen(data); i++)
if (isdigit(data[i]))
data2[ii++] = data[i];
}
for (i=0;i<=6;i++)
{
k = atol(data2);
{
fscanf(fptdrill,"%s",data);
printf("\t atol test:%ld\n",k);
}
}
}
}
}
The display result is like:
data[0]=A11111 atol test=77777
data[1]=B22222 atol test=77777
data[2]=B33333 atol test=77777
....
data[6]=B77777 atol test=77777
The display result is not satisfied for me. Actually I need to display the result something like this:
data[0]=A11111 atol test=11111
data[1]=B22222 atol test=22222
data[2]=B33333 atol test=...
data[3]=B44440 ---(need to add zero)
data[4]=A55555---(B66666 need to be entered to the next line)
data[5]=B66666....
data[6]=B77777 ....
...
Please help me...:cool: