I've been working with data written in .txt files and so had some problems.
Example of data: lettts ddo ttttthis
Example of answer: le3ts 2do 5this
I've tried to read 2 times information while second time ignoring first character and below the read function compare with for loop if(char1==char2) count++;
But all it does is making all chars equal.
Any suggestions how to compare chars properly?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch,ch2,chvoid;
int i,num=0,num2=0;
FILE *fp;
if (fp = fopen("file.txt", "r"))
{
while (ch != EOF)
{
ch = getc(fp);
printf("%c", ch);
}
fclose(fp);
}
if (fp = fopen("file.txt", "r"))
{
chvoid = getc(fp);
while (ch2 != EOF)
{
ch2 = getc(fp);
printf("%c", ch2);
num++;
}
fclose(fp);
}
for(i=1;i<num;i++){
if(ch!=ch2){
printf("test");
}
if(ch==ch2){
num2++;
printf("%d ",num2);
}
num2=0;
}
return 0;
}