In a text file I have "abbcccdddd". I want to store "abcd" in an array.
Before: tx[0] = a, tx[1] = b, tx[3] = c, tx[6] = d
After: tx[0] = a, tx[1] = b, tx[2] = c, tx[3] = d
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
FILE *fp = fopen("D:\\C#\\Zip\\Text001.txt", "r");
char x;
int size;
int j, k;
int i = 0;
fseek(fp, 0, SEEK_END);
size = ftell(fp);
fseek(fp, 0, SEEK_SET);
char tx[size];
x = fgetc(fp);
while (x != EOF)
{
tx[i] = x;
printf("%c", tx[i]);
x = fgetc(fp);
i++;
}
}
aabbccaabbcc, do you want the output to beabcabcorabc? The first is a lot easier than the second.