X1.txt
Code:
July15
July1
August15
August1
I managed to get something done using C since my previous question. I finally thought to extract the lines I needed instead of deleting the ones I don’t. I’ts not perfect but it’s better then nothing. Now I’m trying to get the digits that are in the first line in a file and copy them to array_2 so that I can operate on it latter. This code can only get one digit and that’s no good. What is needed to make this work?
Code:
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#define BUFFER_MAX 512
#define MEM (BUFFER_MAX+1)
FILE *fptr, *fptw;
char array_1[MEM];
char array_2[MEM];
int main()
{
unsigned int len1;
unsigned int len2;
fptw = fopen("X2.txt", "w");
fclose(fptw);
// read file into a buffer.
fptr = fopen("X1.txt", "r");
len1 = fread(array_1, sizeof(char), BUFFER_MAX, fptr);
array_1[len1] = '\0';
fclose(fptr);
// get digits from the first line in a file.
char *s = array_1;
if (!isdigit(*s)) {
while (*s && !isdigit(*++s));
}
if (*s)
putchar(*s);
printf(" size=\%db. One number missing.\n", len1);
return 0;
}
Result: 1 size=30b. one number missing.