working on a string tough string prog, need help

This is a discussion on working on a string tough string prog, need help within the C Programming forums, part of the General Programming Boards category; the program i am working on will read a dictionary file with over 25000 words. it will check for repeating ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    13

    Unhappy working on a string tough string prog, need help

    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.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    With a dictionary of over 25,000 words, it is quite possible to have many words that are the same length with 4 and 5 repeated characters. Thus, I would suggest you use a singly linked list for storing these words. Find and delete functions would have to be implemented for the SLL in order to replace the old short word with a new short word.

    Also, IMHO, a singly linked list would be ideal for the singular and cumulative stem sequences.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  2. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 11:32 AM
  5. string handling
    By lessrain in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 08:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21