在文本文件中,我有「abbcccdddd」。我想將「abcd」存儲在一個數組中。C刪除char數組中的重複字符
之前:TX [0] = A,TX [1] = B,TX [3] = C,TX [6] = d
後: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++;
}
}
爲什麼輸出ABC,而不是ABCD? – GoodDeeds
你的嘗試似乎根本沒有任何嘗試。它只是讀取文件中的數據。這會讓你看到你描述的*起點。 –
當您從文件中讀取字符時,重複刪除會更容易,因此數組永遠不會重複運行重複字符。你可以通過對你已有的東西進行一些小修改來完成。 –