the program i am working on will read a dictionary file with over 25000 words. it will check for repeating characters, if there are 4 characters repeated in a string then it prints out that straing with a * at the end, if 5 characters are repated then ** at the end. so far i got this to work great, but i also need so at the end of everything, it prints out the SHORTEST string with 4 repeated characters and the SHORTEST string with 5 repeated characters.
Heres my code:
Code:
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int charrepeatamount (char [], char );
void addasterisks(char []);
int main()
{
char string1[25],string2[25],string3[25];
int flag;
char short5[25];
/*flag=*/scanf("%25s",&string1);
/*while(flag != EOF) //add when prog done
{*/
addasterisks(string1);
scanf("%25s",&string2);
addasterisks(string2);
scanf("%25s",&string3);
addasterisks(string3);
/*if((strlen(string1)>=4)&&(strspn(string1,string2)==strspn(string3,string2)))
printf("3");*/ //for next part of program
scanf("%25s",&string1);
/* }*/
}
int charrepeatamount (char string[], char character)
{
char *pt;
int i=0;
pt=strchr(string,character);
if(pt == NULL)
return -1;
while(pt != NULL)
{
i++;
pt=strchr(pt+1,character);
}
return i;
}
void addasterisks(char string[])
{
int i,timesrepeated;
int repeated4times=0,repeated5times=0,strlength;
for(i=0;i<strlen(string);i++)
{
timesrepeated=charrepeatamount(string,string[i]);
if(timesrepeated==4)
repeated4times++;
if(timesrepeated==5)
repeated5times++;
}
if(repeated4times > 0)
{
strcat(string,"*");
puts(string);
}
if(repeated5times > 0)
{
strlength=strlen(string);
if(string[strlength-1]=='*')
string[strlength-1]='\0';
strcat(string,"**");
puts(string);
}
}
Also the long "if" statement you see commented out in middle of the program is for the second part of the program. For the second part i need the program to text for singular and cumulative stem sequences. a singular stem sequence for example:
above
aboveboard
aboveground
abovemention
where first string is the begining of next few strings
cumulative example:
alga
algae
algaecide
where first string is the begining of the next string and the second string is the beginging of the 3rd.
At the end it should print out the length of longest stem sequence.
Any help would be greatly appricated.