I need to count to two sentences words, but I only count one sentences words.

This is a discussion on I need to count to two sentences words, but I only count one sentences words. within the C Programming forums, part of the General Programming Boards category; Here is my current code: Code: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #define LINES 4096 char red; char* ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    229

    I need to count to two sentences words, but I only count one sentences words.

    Here is my current code:

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ctype.h>
    #define LINES 4096
      
    char red;
    char* reverse;
     
    /* The function to split the input into a sentence per line */
    int split_by_sentence(void)
    {
    	int character, file_character=0;
    	char buffer[1024];
    	FILE *book=fopen("readtext1.txt", "r");
    	FILE *book2=fopen("readtext.txt", "a+");
    	if(!book) {printf("Error: unable to open input file!\n"); return 1;}
    	if(!book2) {printf("Error: unable to open output file!\n"); return 1;}
    
    	while(file_character!=EOF)
    	{
    		buffer[0]='\0';
    		for(character=0;character<sizeof(buffer);character++) 
    		{
    			file_character=fgetc(book);
    			if(file_character==EOF)
    				break;
    			
    			if(file_character=='.')
    			{
    				buffer[character]='\0';  
    				break;
    			}
    			
    			if(file_character=='?')
    			{
    				buffer[character]='\0';  
    				break;
    			}
    			
    			if(file_character=='!')
    			{
    				buffer[character]='\0';  
    				break;
    			}
    			
    			buffer[character]=file_character;
    		}
    		
    		if(file_character==EOF)
    			break;
    		fprintf(book2, "%s.\n", buffer);
    	}
    	fclose(book);
    	fclose(book2);
    	putchar('\n');
    	
    	return 0;
    }
     
    /* The function to find the first letter in the word */
    char find_letter (char* a, char* b)
    {
    	char string = strlen(b);
        strncpy (a,b,1);
        a[1]='\0';
        return 0;
    }
    
    /* The function to reverse the characters in a string */
    char* rev(char* str)
    {
    	int end= strlen(str)-1;
    	int start = 0;
    	
    	while( start<end )
    	{
    		char temp = str[ start ];
    		str[ start ] = str[ end ];
    		str[ end ] = temp;
    		
    		++start;
    		--end;
    	}
    	
    	return str;
    }
    
    /* The function for percentage calculation */
    void percentage_calculation_numbers(char* a_pch, char* a_b)
    {
    	FILE *fp;
        char str2[7];
        char vowels[] = "aeiouyAEIOUY";
        char letters[] = "bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXYZ";
        char alphabet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	int count_point = 0;
    	int count_shoot = 0;
    	int count_reload = 0;
    	int count_autofire = 0;
        float one;
        float two;
        float three;
        float four;
        float total;
        float five;
        float six;
        float seven;
        float eight;
        float total_2;
        float percentage_1;
        float percentage_2;
        float percentage_3;
        float percentage_4;
         
        one = 0;
        two = 0;
        three = 0;
        four = 0;
        total = 0;
        five = 0;
        six = 0;
        seven = 0;
        eight = 0;
        total_2 = 0;
        percentage_1 = 0;
        percentage_2 = 0;
        percentage_3 = 0;
        percentage_4 = 0;
    	
    	/* open text file or report error */
    	fp = fopen("writelist.txt", "a+");
      
        if((fp = fopen("writelist.txt", "a+"))==NULL) 
    	{
        printf("Cannot open file.\n");
        exit(1);
        }
    
    	/*This printf and fprintf isn't needed while I create the code function, so I'll comment it out
        printf("%s\n\n", a_pch);
        fprintf(fp, "%s\n\n", a_pch);*/
        
    	/* The while loop gives value to five, six, seven, eight, which is used for the percentage calculation */
    	while(a_pch != NULL)
    	{
    		/* identify the first letter in the word begin */
              
            red = find_letter(str2, a_pch);
            
    		if(strpbrk(str2, letters))
            {
    			one++;
            }
            
    		if(strpbrk(str2, vowels))
            {
    			two++;
            }
            
    		/* identify the first letter in the word end */
    		
    		/* identify the last letter in the word begin */
            
    		reverse = rev(a_pch);
    		red = find_letter(str2, a_pch);
            
    		if(strpbrk(str2, letters))
            {
    			three++;
            }
            
    		if(strpbrk(str2, vowels))
            {
    			four++;
            }
            
    		/* identify the last letter in the word end */
    
            /* The math using the first and last letter begin */
    
    		/* pch is backwards, so I use rev to reverse it back */
    		/*printf("%s uncomment to test to see if the string is backwards", pch);*/
    		reverse = rev(a_pch);
    
            if(total = (one && three))
            {
    			count_point++;
    			five++;
    			printf("%s point %d\n", a_pch, count_point);
    			fprintf(fp, "%s point %d\n", a_pch, count_point);
            }
            
    		else if(total = (one && four))
            {
    			count_shoot++;
    			six++;
    			printf("%s shoot %d\n", a_pch, count_shoot);
    			fprintf(fp, "%s shoot %d\n", a_pch, count_shoot);
            }
            
    		else if(total = (two && three))
            {
    			count_reload++;
    			seven++;
    			printf("%s reload %d\n", a_pch, count_reload);
    			fprintf(fp, "%s reload %d\n", a_pch, count_reload);
            }
            
    		else if(total = (two && four))
            {
    			count_autofire++;
    			eight++;
    			printf("%s autofire %d\n", a_pch, count_autofire);
    			fprintf(fp, "%s autofire %d\n", a_pch, count_autofire);
            }
            
    		/* The math using the first and last letter end */
      
            /* Reset the pointers */
    		
    		one = 0;
            two = 0;
            three = 0;
            four = 0;
            total = 0;
            
    		a_pch = strtok (NULL, " .");
    	}
    	/* Add separation between lines in text file so sentences can be identified */
    	putchar('\n');
    	fputc ('\n', fp);
    
    	/* pch is NULL, so I find alphabet in b and pass that into pch */
    	a_pch = strpbrk(a_b, alphabet);
    	
    	/* I'm commenting out the three secotions below that make the percentage because I don't know how to use it effectively yet */
    
    	/* Count the pointers */
    	/*total_2 = (five + six + seven + eight);
    	percentage_1 = ((five)/ total_2);
    	percentage_2 = ((six)/ total_2);
    	percentage_3 = ((seven)/ total_2);
    	percentage_4 = ((eight)/ total_2);*/
    	
    	/* Display the results in the console window */
    	/*printf("\n\nletter vowel letter %f\nletter vowel vowel %f\nvowel vowel letter %f\nvowel vowel vowel %f\n\n", 
    		percentage_1, percentage_2, percentage_3, percentage_4);*/
    	
    	/* Write the pointers result to file */
    	/*fprintf(fp, "\n\nletter vowel letter %f\nletter vowel vowel %f\nvowel vowel letter %f\nvowel vowel vowel %f\n\n", 
    		percentage_1, percentage_2, percentage_3, percentage_4);*/
    
    	fclose(fp);
    }
    
    /* function to find pattern, useful to identify how the words parallel a syllogism */
    int find_pattern(void)
    {
    	int count_one = 0, count_two = 0, count_three = 0, count_four = 0;
    	int count_five = 0, count_six = 0, count_seven = 0, count_eight = 0;
        char buffer[LINES];
    	char point_1 [300];
    	char point_2 [300];
    	char shoot_1 [300];
    	char shoot_2 [300];
    	char shoot_3 [300];
        char reload_1 [300];
    	char reload_2 [300];
    	char autofire_1 [300];
    	char autofire_2 [300];
    
        FILE *book=fopen("writelist.txt", "r");
        if(!book) {printf("Error: unable to open input file!\n"); return 1;}
    	while(fgets(buffer, sizeof(buffer), book)!=NULL)
    	{
    		if (strstr(buffer, "point 1"))
    		{
    			strcpy(point_1, buffer);
    		}
    		if (strstr(buffer, "point 2"))
    		{
    			strcpy(point_2, buffer);
    		}
    		if (strstr(buffer, "shoot 1"))
    		{
    			strcpy(shoot_1, buffer);
    		}
    		if (strstr(buffer, "shoot 2"))
    		{
    			strcpy(shoot_2, buffer);
    		}
    		if (strstr(buffer, "shoot 3"))
    		{
    			strcpy(shoot_3, buffer);
    		}
    		if (strstr(buffer, "reload 1"))
    		{
    			strcpy(reload_1, buffer);
    		}
    		if (strstr(buffer, "reload 2"))
    		{
    			strcpy(reload_2, buffer);
    		}
    		if (strstr(buffer, "autofire 1"))
    		{
    			strcpy(autofire_1, buffer);
    		}
    		if (strstr(buffer, "autofire 2"))
    		{
    			strcpy(autofire_2, buffer);
    		}
    	}
    	
    		
    	if(strstr(reload_1, "reload 1"))
    	{
    		if(strstr(point_1, "point 1"))
    		{
    			if(strstr(autofire_1, "autofire 1"))
    			{
    				if(strstr(point_2, "point 2"))
    				{
    					count_one++;
    				}
    			}
    		}
    	}
    
    	if(strstr(shoot_1, "shoot 1"))
    	{
    		if(strstr(point_1, "point 1"))
    		{
    			if(strstr(reload_1, "reload 1"))
    			{
    				if(strstr(point_2, "point 2"))
    				{
    					count_two++;
    				}
    			}
    		}
    	}
       fclose(book);
       printf("one %d\n", count_one);
       printf("two %d\n", count_two);
       /* The syllogism uses the scope twice, so if the count equals 2 there is a syllogism pattern */
       if(count_one > count_two)
       {
    	   printf("Type Darapti (AAI-3)_or_Barbari (AAI-1)_or_Barbara (AAA-1) Syllogism pattern found\n\n");
       }
       if(count_two > count_one)
       {
    	   printf("Type Ferio (EIO-1) Syllogism pattern found\n\n");
       }
    
       return 0;
    }
    
    /* function so I don't have to type getch all over the place */
    void MyExit(void) { system("pause"); }
       
    /* the main program */ 
    int main ()
    {   
    	/* declaring and initiaizing variables */
    	FILE *book;
    	char * pch = malloc(300);
    	char alphabet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	char buffer[LINES];
    
    	/* The function is called so I don't have to type getch */
    	atexit(MyExit);    
    	
    	/* The function is called and creates the text file */
    	split_by_sentence();
    	
    	/* The text file just created is opened */
    	book = fopen("readtext.txt", "r");
    	
    	if(!book)   
    	{
    		perror("Error: file readtext.txt was not found or opened");   
    		return 0;   
    	}
    	
    	/* read from file */
    	while(fgets(buffer, sizeof(buffer), book)!=NULL)
    	{ 
    		/* I tokenize the input string into individual words */
    		pch = strtok (buffer, " ~!@#$%^&*()_+`1234567890-=[]\'\"/;/|,./{}:<>?");
    		
    		/* I find the alphabet in pch after it's run through strtok */
    		if(strpbrk(pch, alphabet))
    		{
    			/* I run the percentage function which also creates the new terms for the words processed */
    			percentage_calculation_numbers(pch, buffer);
    		}
    	}
    		fclose(book);
    		find_pattern();
    		return 0;
    }
    Here is the current code:


    The syllogism pattern I use in the scope in the find_pattern() function is split over two sentences.

    The problem is that the function percentage_calculation_numbers() writes the "count_" of one sentence.

    So when the find_pattern() function counts the number of words it only counts one sentence.
    find_pattern() needs to count two sentences.

    My two problems:
    1) I don't know how to get the find_pattern() function to use only one sentence.
    2) I don't know how to get the percentage_calculation_numbers() to count more than one sentence in "count_".

    The syllogism I have in readtext1.txt works fine now when I run the program.
    I'm not too sure how to fix my two problems.

    Here is the contents of readtext1.txt:
    Code:
    No homework is fun.
    Some reading is homework.
    writelist.txt and readlist.txt are blank when you run the program.

    I'll probably only get Adak's help so may I ask for a code example, sir?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Too simple, Jeremy. Just stracat sentence two onto the end of sentence one.

    Code:
    strcat(sentence1, sentence2);
    And then send the combined sentence out to be analyzed. You may need to add strcat a space onto the end of sentence1 first, to keep that space after the period.

    You'll need to have the room for your (now) larger sentence, of course.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    In a while loop using fgets to go through a file line by line.
    I used strcpy to copy buffer from fgets to a char variable.

    I then put a printf below the char variable to see the results.
    The file fgets reads has two sentences on two different lines and printf displays three individual lines.

    If I put printf outside the while loop I only see the last line from the input file.

    So if I'm going to use strcat to join two sentences it needs to be done inside the while loop.
    For a single sentence I need to strcpy a buffer from one loop to a char variable.
    I need two sentences, so after the first loop I need to send buffer into the second char variable.

    The problem
    I don't know how to send buffer into one char variable in one loop,
    and the next loop send buffer into a different char variable.
    If I did then I could use strcat to join the two sentences in the two char variables.

    It seems to me that using strcat is the wrong idea.
    I mean it sounds simple but the implementation is really difficult to problem solve to me.
    I've been at this for over an hour figuring out what I just told you in this post.
    I think I need some kind of for loop in the while loop in the main function, but what kind or how it works I have no idea.

    Edit,

    I'm going to go a different route, Adak.
    I have the list of different scopes to make and than I just need to write them into the find pattern function and test it and everything is fine.
    I was hesitant to go this way before I posted this thread but I will try now anyway.
    Here is what I wrote below and will put into the find pattern function:

    Code:
    reload 1
    point 1
    autofire 1
    point 2
    
    = 1
    
    reload 1
    point 1
    shoot 1
    point 2
    
    = 2
    
    
    reload 1
    autofire 1
    point 1
    autofire 2
    reload 2
    
    = 3
    
    shoot 1
    point 1
    shoot 2
    point 2
    
    = 4
    
    shoot 1
    point 1
    reload 1
    point 2
    
    = 5
    
    shoot 1
    point 1
    autofire 1
    point 2
    
    = 6
    
    shoot 1
    point 1
    autofire 1
    reload 1
    
    = 7
    
    shoot 1
    point 1
    autofire 1
    point 2
    reload 1
    
    = 8
    
    shoot 1
    point 1
    shoot 2
    shoot 3
    point 2
    
    = 9
    
    Darapti (AAI-3)_or_Barbari (AAI-1)_or_Barbara (AAA-1)
    = 1
    
    Ferio (EIO-1)
    = 5
    
    Celaront (EAO-1)_or_Celarent (EAE-1)
    = 4, 1
    
    Darii (AII-1)
    = 2, 6
    
    Baroco (AOO-2)
    = 3, 8
    
    Bocardo (OAO-3)
    = 9, 1
    
    Camestros (AEO-2)
    = 2, 4
    
    Felapton (EAO-3)
    = 7, 1
    I will post my finished code later.
    Last edited by jeremy duncan; 11-22-2011 at 09:00 PM.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    Here is my current code:

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ctype.h>
    #define LINES 4096
      
    char red;
    char* reverse;
     
    /* The function to split the input into a sentence per line */
    int split_by_sentence(void)
    {
    	int character, file_character=0;
    	char buffer[1024];
    	FILE *book=fopen("readtext1.txt", "r");
    	FILE *book2=fopen("readtext.txt", "a+");
    	if(!book) {printf("Error: unable to open input file!\n"); return 1;}
    	if(!book2) {printf("Error: unable to open output file!\n"); return 1;}
    
    	while(file_character!=EOF)
    	{
    		buffer[0]='\0';
    		for(character=0;character<sizeof(buffer);character++) 
    		{
    			file_character=fgetc(book);
    			if(file_character==EOF)
    				break;
    			
    			if(file_character=='.')
    			{
    				buffer[character]='\0';  
    				break;
    			}
    			
    			if(file_character=='?')
    			{
    				buffer[character]='\0';  
    				break;
    			}
    			
    			if(file_character=='!')
    			{
    				buffer[character]='\0';  
    				break;
    			}
    			
    			buffer[character]=file_character;
    		}
    		
    		if(file_character==EOF)
    			break;
    		fprintf(book2, "%s.\n", buffer);
    	}
    	fclose(book);
    	fclose(book2);
    	putchar('\n');
    	
    	return 0;
    }
     
    /* The function to find the first letter in the word */
    char find_letter (char* a, char* b)
    {
    	char string = strlen(b);
        strncpy (a,b,1);
        a[1]='\0';
        return 0;
    }
    
    /* The function to reverse the characters in a string */
    char* rev(char* str)
    {
    	int end= strlen(str)-1;
    	int start = 0;
    	
    	while( start<end )
    	{
    		char temp = str[ start ];
    		str[ start ] = str[ end ];
    		str[ end ] = temp;
    		
    		++start;
    		--end;
    	}
    	
    	return str;
    }
    
    /* The function for percentage calculation */
    void percentage_calculation_numbers(char* a_pch, char* a_b)
    {
    	FILE *fp;
        char str2[7];
        char vowels[] = "aeiouyAEIOUY";
        char letters[] = "bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXYZ";
        char alphabet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        float one;
        float two;
        float three;
        float four;
        float total;
        float five;
        float six;
        float seven;
        float eight;
        float total_2;
        float percentage_1;
        float percentage_2;
        float percentage_3;
        float percentage_4;
         
        one = 0;
        two = 0;
        three = 0;
        four = 0;
        total = 0;
        five = 0;
        six = 0;
        seven = 0;
        eight = 0;
        total_2 = 0;
        percentage_1 = 0;
        percentage_2 = 0;
        percentage_3 = 0;
        percentage_4 = 0;
    	
    	/* open text file or report error */
    	fp = fopen("writelist.txt", "a+");
      
        if((fp = fopen("writelist.txt", "a+"))==NULL) 
    	{
        printf("Cannot open file.\n");
        exit(1);
        }
    
    	/* Displays the first letter of the sentence above the list made in the while loop
    	So in large articles you can find the sentence being counted.*/
    	printf("%s\n\n", a_pch);
        
    	/* The while loop gives value to five, six, seven, eight, which is used for the percentage calculation */
    	while(a_pch != NULL)
    	{
    		/* identify the first letter in the word begin */
              
            red = find_letter(str2, a_pch);
            
    		if(strpbrk(str2, letters))
            {
    			one++;
            }
            
    		if(strpbrk(str2, vowels))
            {
    			two++;
            }
            
    		/* identify the first letter in the word end */
    		
    		/* identify the last letter in the word begin */
            
    		reverse = rev(a_pch);
    		red = find_letter(str2, a_pch);
            
    		if(strpbrk(str2, letters))
            {
    			three++;
            }
            
    		if(strpbrk(str2, vowels))
            {
    			four++;
            }
            
    		/* identify the last letter in the word end */
    
            /* The math using the first and last letter begin */
    
    		/* pch is backwards, so I use rev to reverse it back */
    		/*printf("%s uncomment to test to see if the string is backwards", pch);*/
    		reverse = rev(a_pch);
    
    		/*The math using the first and last letter begin
    		Here I give the word a new string value, based on how the vowel is situated in the word.*/
    
            if(total = (one && three))
            {
    			five++;
    			printf("point\n");
    			fprintf(fp, "point\n");
            }
            
    		else if(total = (one && four))
            {
    			six++;
    			printf("shoot\n");
    			fprintf(fp, "shoot\n");
            }
            
    		else if(total = (two && three))
            {
    			seven++;
    			printf("reload\n");
    			fprintf(fp, "reload\n");
            }
            
    		else if(total = (two && four))
            {
    			eight++;
    			printf("autofire\n");
    			fprintf(fp, "autofire\n");
            }
            
    		/* The math using the first and last letter end */
      
            /* Reset the pointers */
    		
    		one = 0;
            two = 0;
            three = 0;
            four = 0;
            total = 0;
            
    		a_pch = strtok (NULL, " .");
    	}
    	/* Add separation between lines in text file so sentences can be identified */
    	putchar('\n');
    	fputc ('\n', fp);
    
    	/* pch is NULL, so I find alphabet in b and pass that into pch */
    	a_pch = strpbrk(a_b, alphabet);
    	
    	/* Count the pointers */
    	total_2 = (five + six + seven + eight);
    	percentage_1 = ((five)/ total_2);
    	percentage_2 = ((six)/ total_2);
    	percentage_3 = ((seven)/ total_2);
    	percentage_4 = ((eight)/ total_2);
    	
    	/* Display the results in the console window */
    	printf("letter vowel letter %f\nletter vowel vowel %f\nvowel vowel letter %f\nvowel vowel vowel %f\n\n", 
    		percentage_1, percentage_2, percentage_3, percentage_4);
    
    	fclose(fp);
    }
    
    /* function to find pattern, useful to identify how the words parallel a syllogism */
    int find_pattern(void)
    {
    	/* declare variable arrays */
    
    	char Darii[] = "reload\npoint\nshoot\npoint\nshoot\npoint\nautofire\npoint";
    	char Camestros[] = "reload\npoint\nshoot\npoint\nshoot\npoint\nshoot\npoint";
    	char Baroco[] = "reload\nautofire\npoint\nautofire\nreload\nshoot\npoint\nautofire\npoint\nreload";
    	char Bocardo[] = "shoot\npoint\nshoot\nshoot\npoint\nreload\npoint\nautofire\npoint";
    	char Celaront[] = "shoot\npoint\nshoot\npoint\nreload\npoint\nautofire\npoint";
    	char Felapton[] = "shoot\npoint\nautofire\nreload\nreload\npoint\nautofire\npoint";
    	char Ferio[] = "shoot\npoint\nreload\npoint\nshoot\npoint\nreload\npoint";
    	char Darapti[] = "reload\npoint\nautofire\npoint\nreload\npoint\nautofire\npoint";
        char buffer[LINES];
    	char pch[LINES];
    
    	/* Read the list made by the percentage function */
    
        FILE *book=fopen("writelist.txt", "r");
        if(!book) {printf("Error: unable to open input file!\n"); return 1;}
    	while(fgets(buffer, sizeof(buffer), book)!=NULL)
    	{
    		/* Find the word then add it the the pch string */
    
    		if (strstr(buffer, "point"))
    		{
    			strcat(pch, buffer);
    		}
    		if (strstr(buffer, "shoot"))
    		{
    			strcat(pch, buffer);
    		}
    		if (strstr(buffer, "reload"))
    		{
    			strcat(pch, buffer);
    		}
    		if (strstr(buffer, "autofire"))
    		{
    			strcat(pch, buffer);
    		}
    	}
       fclose(book);
       
       /* Compare the pch string to the declared variable arrays */
       
       if(strstr(pch, Darii))
       {
    	   printf("Type Darii (AII-1) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Camestros))
       {
    	   printf("Type Camestros (AEO-2) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Baroco))
       {
    	   printf("Type Baroco (AOO-2) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Bocardo))
       {
    	   printf("Type Bocardo (OAO-3) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Celaront))
       {
    	   printf("Type Celaront (EAO-1)_or_Celarent (EAE-1) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Felapton))
       {
    	   printf("Type Felapton (EAO-3) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Ferio))
       {
    	   printf("Type Ferio (EIO-1) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Darapti))
       {
    	   printf("Type Darapti (AAI-3)_or_Barbari (AAI-1)_or_Barbara (AAA-1) Syllogism pattern found\n\n");
       }
    
       return 0;
    }
    
    /* function so I don't have to type getch all over the place */
    void MyExit(void) { system("pause"); }
       
    /* the main program */ 
    int main ()
    {   
    	/* declaring and initiaizing variables */
    	FILE *book;
    	char * pch = malloc(300);
    	char alphabet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	char buffer[LINES];
    
    	/* The function is called so I don't have to type getch */
    	atexit(MyExit);    
    	
    	/* The function is called and creates the text file */
    	split_by_sentence();
    	
    	/* The text file just created is opened */
    	book = fopen("readtext.txt", "r");
    	
    	if(!book)   
    	{
    		perror("Error: file readtext.txt was not found or opened");   
    		return 0;   
    	}
    	
    	/* read from file */
    	while(fgets(buffer, sizeof(buffer), book)!=NULL)
    	{ 
    		/* I tokenize the input string into individual words */
    		pch = strtok (buffer, " ~!@#$%^&*()_+`1234567890-=[]\'\"/;/|,./{}:<>?");
    		
    		/* I find the alphabet in pch after it's run through strtok */
    		if(strpbrk(pch, alphabet))
    		{
    			/* I run the percentage function which also creates the new terms for the words processed */
    			percentage_calculation_numbers(pch, buffer);
    		}
    	}
    		fclose(book);
    		find_pattern();
    		return 0;
    }
    Here are the syllogisms main and minor premise.
    Code:
    Barbara (AAA-1)
    All men are mortal.
    All Greeks are men.
    
    Celarent (EAE-1)
    No reptiles have fur.
    All snakes are reptiles.
    
    Darii (AII-1)
    All rabbits have fur.
    Some pets are rabbits.
    
    Ferio (EIO-1)
    No homework is fun.
    Some reading is homework.
    
    Baroco (AOO-2)
    All informative things are useful.
    Some websites are not useful.
    
    Bocardo (OAO-3)
    Some cats have no tails.
    All cats are mammals.
    
    Barbari (AAI-1)
    All men are mortal.
    All Greeks are men.
    
    Celaront (EAO-1)
    No reptiles have fur.
    All snakes are reptiles.
    
    Camestros (AEO-2)
    All horses have hooves.
    No humans have hooves.
    
    Felapton (EAO-3)
    No flowers are animals.
    All flowers are plants.
    
    Darapti (AAI-3)
    All squares are rectangles.
    All squares are rhombs.
    Here is the contents of readtext1.txt holding one syllogism:

    Code:
    All horses have hooves.
    No humans have hooves.
    So the program runs fine without the find pattern function, and if I put the find pattern function in the program the program runs fine when I use any of the syllogisms from that list.

    But if I put a big article in readtext1 the program crashes.
    It's crashing because of the find pattern function and I don't know why.
    Can you look to see why, Adak and post telling me how to fix it, please.
    Last edited by jeremy duncan; 11-23-2011 at 02:40 AM.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You're overfilling the array with strcat (pch,buffer), is the likely reason. Either make it larger, or become more selective about what is going into any one array.

    Do a print out of strlen() on those two buffers, when it has text that makes it crash, before it does crash. (Maybe one after each strcat(), and see what the sizes really are.

  6. #6
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    I decided to be selective about what goes into the strcat(pch, buffer).
    What I want to happen in the find pattern function is to count how many times char "LINES" is used by strcat.
    I only want LINES to be filled twice, so there is two sentences in the LINES, then to reset lines so no strcat sentences are in there.
    I want to do this for all the sentences find pattern receives, fill LINES with two sentences, erase the sentences from LINES, then start over again.
    After LINES has two sentences I want to test to see if it matches a syllogism.

    I think I may need some kind of fancy for loop to count the sentences find_pattern() receives.
    Can you think of a solution for what I want to do and post some example code so I can work on it?

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I have not understood what you're doing, for several weeks now. I mean, specifically. Writing code would be pure guess work, and "Duncan" is Scottish, and everyone knows that it's the Irish who are lucky, naught da Scot'ish, d'ya nae ken?

    If you delete the first char of the array - set it to '\0', at the end of each analysis of that string, then your problems should be over. At least, I think so.

    Give that a try.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    I have not understood what you're doing, for several weeks now.
    ... neither does he.

  9. #9
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    I was able to get the program not to crash when I input a large text file.
    Here is the current code:

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ctype.h>
    #define LINES 4096
      
    char red;
    char* reverse;
     
    /* The function to split the input into a sentence per line */
    int split_by_sentence(void)
    {
    	int character, file_character=0;
    	char buffer[1024];
    	FILE *book=fopen("readtext1.txt", "r");
    	FILE *book2=fopen("readtext.txt", "a+");
    	if(!book) {printf("Error: unable to open input file!\n"); return 1;}
    	if(!book2) {printf("Error: unable to open output file!\n"); return 1;}
    
    	while(file_character!=EOF)
    	{
    		buffer[0]='\0';
    		for(character=0;character<sizeof(buffer);character++) 
    		{
    			file_character=fgetc(book);
    			if(file_character==EOF)
    				break;
    			
    			if(file_character=='.')
    			{
    				buffer[character]='\0';  
    				break;
    			}
    			
    			if(file_character=='?')
    			{
    				buffer[character]='\0';  
    				break;
    			}
    			
    			if(file_character=='!')
    			{
    				buffer[character]='\0';  
    				break;
    			}
    			
    			buffer[character]=file_character;
    		}
    		
    		if(file_character==EOF)
    			break;
    		fprintf(book2, "%s.\n", buffer);
    	}
    	fclose(book);
    	fclose(book2);
    	putchar('\n');
    	
    	return 0;
    }
     
    /* The function to find the first letter in the word */
    char find_letter (char* a, char* b)
    {
    	char string = strlen(b);
        strncpy (a,b,1);
        a[1]='\0';
        return 0;
    }
    
    /* The function to reverse the characters in a string */
    char* rev(char* str)
    {
    	int end= strlen(str)-1;
    	int start = 0;
    	
    	while( start<end )
    	{
    		char temp = str[ start ];
    		str[ start ] = str[ end ];
    		str[ end ] = temp;
    		
    		++start;
    		--end;
    	}
    	
    	return str;
    }
    
    /* The function for percentage calculation */
    void percentage_calculation_numbers(char* a_pch, char* a_b)
    {
    	FILE *fp;
        char str2[7];
        char vowels[] = "aeiouyAEIOUY";
        char letters[] = "bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXYZ";
        char alphabet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        float one;
        float two;
        float three;
        float four;
        float total;
        float five;
        float six;
        float seven;
        float eight;
        float total_2;
        float percentage_1;
        float percentage_2;
        float percentage_3;
        float percentage_4;
         
        one = 0;
        two = 0;
        three = 0;
        four = 0;
        total = 0;
        five = 0;
        six = 0;
        seven = 0;
        eight = 0;
        total_2 = 0;
        percentage_1 = 0;
        percentage_2 = 0;
        percentage_3 = 0;
        percentage_4 = 0;
    	
    	/* open text file or report error */
    	fp = fopen("writelist.txt", "a+");
      
        if((fp = fopen("writelist.txt", "a+"))==NULL) 
    	{
        printf("Cannot open file.\n");
        exit(1);
        }
    
    	/* Displays the first letter of the sentence above the list made in the while loop
    	So in large articles you can find the sentence being counted.*/
    	printf("%s\n\n", a_pch);
        
    	/* The while loop gives value to five, six, seven, eight, which is used for the percentage calculation */
    	while(a_pch != NULL)
    	{
    		/* identify the first letter in the word begin */
              
            red = find_letter(str2, a_pch);
            
    		if(strpbrk(str2, letters))
            {
    			one++;
            }
            
    		if(strpbrk(str2, vowels))
            {
    			two++;
            }
            
    		/* identify the first letter in the word end */
    		
    		/* identify the last letter in the word begin */
            
    		reverse = rev(a_pch);
    		red = find_letter(str2, a_pch);
            
    		if(strpbrk(str2, letters))
            {
    			three++;
            }
            
    		if(strpbrk(str2, vowels))
            {
    			four++;
            }
            
    		/* identify the last letter in the word end */
    
            /* The math using the first and last letter begin */
    
    		/* pch is backwards, so I use rev to reverse it back */
    		/*printf("%s uncomment to test to see if the string is backwards", pch);*/
    		reverse = rev(a_pch);
    
    		/*The math using the first and last letter begin
    		Here I give the word a new string value, based on how the vowel is situated in the word.*/
    
            if(total = (one && three))
            {
    			five++;
    			printf("point\n");
    			fprintf(fp, "point\n");
            }
            
    		else if(total = (one && four))
            {
    			six++;
    			printf("shoot\n");
    			fprintf(fp, "shoot\n");
            }
            
    		else if(total = (two && three))
            {
    			seven++;
    			printf("reload\n");
    			fprintf(fp, "reload\n");
            }
            
    		else if(total = (two && four))
            {
    			eight++;
    			printf("autofire\n");
    			fprintf(fp, "autofire\n");
            }
            
    		/* The math using the first and last letter end */
      
            /* Reset the pointers */
    		
    		one = 0;
            two = 0;
            three = 0;
            four = 0;
            total = 0;
            
    		a_pch = strtok (NULL, " .");
    	}
    	/* Add separation between lines in console window, to identify sentence separation*/
    	putchar('\n');
    
    	/* pch is NULL, so I find alphabet in b and pass that into pch */
    	a_pch = strpbrk(a_b, alphabet);
    	
    	/* Count the pointers */
    	total_2 = (five + six + seven + eight);
    	percentage_1 = ((five)/ total_2);
    	percentage_2 = ((six)/ total_2);
    	percentage_3 = ((seven)/ total_2);
    	percentage_4 = ((eight)/ total_2);
    	
    	/* Display the results in the console window */
    	printf("letter vowel letter %f\nletter vowel vowel %f\nvowel vowel letter %f\nvowel vowel vowel %f\n\n", 
    		percentage_1, percentage_2, percentage_3, percentage_4);
            
       /* puts a period into the textfile after a sentence is processed
       This way I can count the number of periods in the text file */
        fprintf(fp, ".\n");
    		
    	fclose(fp);
    }
    
    /* function to find pattern, useful to identify how the words parallel a syllogism */
    int find_pattern(void)
    {
    	/* declare variable arrays */
    	int period = 0;
    	int one = 1;
    
    	char Darii[] = "reload\npoint\nshoot\npoint\nshoot\npoint\nautofire\npoint";
    	char Camestros[] = "reload\npoint\nshoot\npoint\nshoot\npoint\nshoot\npoint";
    	char Baroco[] = "reload\nautofire\npoint\nautofire\nreload\nshoot\npoint\nautofire\npoint\nreload";
    	char Bocardo[] = "shoot\npoint\nshoot\nshoot\npoint\nreload\npoint\nautofire\npoint";
    	char Celaront[] = "shoot\npoint\nshoot\npoint\nreload\npoint\nautofire\npoint";
    	char Felapton[] = "shoot\npoint\nautofire\nreload\nreload\npoint\nautofire\npoint";
    	char Ferio[] = "shoot\npoint\nreload\npoint\nshoot\npoint\nreload\npoint";
    	char Darapti[] = "reload\npoint\nautofire\npoint\nreload\npoint\nautofire\npoint";
        char buffer[LINES];
    	char pch[LINES];
    
    	/* Read the list made by the percentage function */
    
        FILE *book=fopen("writelist.txt", "r");
        if(!book) {printf("Error: unable to open input file!\n"); return 1;}
    	while(fgets(buffer, sizeof(buffer), book)!=NULL)
    	{
    		/* Find the word then add it the the pch string */
    		if (strstr(buffer, "point"))
    		{
    			strcat(pch, buffer);
    		}
    		if (strstr(buffer, "shoot"))
    		{
    			strcat(pch, buffer);
    		}
    		if (strstr(buffer, "reload"))
    		{
    			strcat(pch, buffer);
    		}
    		if (strstr(buffer, "autofire"))
    		{
    			strcat(pch, buffer);
    		}
    		
    		/* counting the periods in the input text file*/
    		if (strstr(buffer, "."))
    		{
    			period++;
    		}
            
            /* After two periods are counted the while loop is exited */
            if(period > one)
            {
                break;
            }
    	}
       fclose(book);
       
       /* Compare the pch string to the declared variable arrays */
       
       if(strstr(pch, Darii))
       {
    	   printf("Type Darii (AII-1) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Camestros))
       {
    	   printf("Type Camestros (AEO-2) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Baroco))
       {
    	   printf("Type Baroco (AOO-2) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Bocardo))
       {
    	   printf("Type Bocardo (OAO-3) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Celaront))
       {
    	   printf("Type Celaront (EAO-1)_or_Celarent (EAE-1) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Felapton))
       {
    	   printf("Type Felapton (EAO-3) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Ferio))
       {
    	   printf("Type Ferio (EIO-1) Syllogism pattern found\n\n");
       }
       else if(strstr(pch, Darapti))
       {
    	   printf("Type Darapti (AAI-3)_or_Barbari (AAI-1)_or_Barbara (AAA-1) Syllogism pattern found\n\n");
       }
       
       /* resetting the pch array to zero, so there is room to fill it again */
       if(period > one)
       {
           memset(&pch[0], 0, sizeof(pch));
           period = 0;
       }
    
       return 0;
    }
    
    /* function so I don't have to type getch all over the place */
    void MyExit(void) { system("pause"); }
       
    /* the main program */ 
    int main ()
    {   
    	/* declaring and initiaizing variables */
    	FILE *book;
    	char * pch = malloc(300);
    	char alphabet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	char buffer[LINES];
    
    	/* The function is called so I don't have to type getch */
    	atexit(MyExit);    
    	
    	/* The function is called and creates the text file */
    	split_by_sentence();
    	
    	/* The text file just created is opened */
    	book = fopen("readtext.txt", "r");
    	
    	if(!book)   
    	{
    		perror("Error: file readtext.txt was not found or opened");   
    		return 0;   
    	}
    	
    	/* read from file */
    	while(fgets(buffer, sizeof(buffer), book)!=NULL)
    	{ 
    		/* I tokenize the input string into individual words */
    		pch = strtok (buffer, " ~!@#$%^&*()_+`1234567890-=[]\'\"/;/|,./{}:<>?");
    		
    		/* I find the alphabet in pch after it's run through strtok */
    		if(strpbrk(pch, alphabet))
    		{
    			/* I run the percentage function which also creates the new terms for the words processed */
    			percentage_calculation_numbers(pch, buffer);
    		}
    	}
    		fclose(book);
    		find_pattern();
    		return 0;
    }
    However I only get the find pattern to work if the syllogism is at the top of the text file.
    I tried other combinations of memset in the find pattern function and the code I have now works.

    What I want to do now after the syllogism is found, is to go back into the while loop and put another two lines into pch.
    The problem is I don't know how to put another two sentences into pch after leaving the while loop.

    And the plan I have is to give each syllogism a percentage value pattern. Then put the percentage into a string value and compare the string like I am now in the find pattern function, then output which syllogism the two sentences match the most, to get a intuitive sense of what the speaker is writing.

    After that I will think fo what to do next, but first I need to solve the problem I am looking at right now, putting another two sentences into pch.

  10. #10
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    I fixed the code. Look at it and see if everything is OK please?

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ctype.h>
    #define LINES 4096
      
    char red;
    char* reverse;
     
    /* The function to split the input into a sentence per line */
    int split_by_sentence(void)
    {
    	int character, file_character=0;
    	char buffer[1024];
    	FILE *book=fopen("readtext1.txt", "r");
    	FILE *book2=fopen("readtext.txt", "a+");
    	if(!book) {printf("Error: unable to open input file!\n"); return 1;}
    	if(!book2) {printf("Error: unable to open output file!\n"); return 1;}
    
    	while(file_character!=EOF)
    	{
    		buffer[0]='\0';
    		for(character=0;character<sizeof(buffer);character++) 
    		{
    			file_character=fgetc(book);
    			if(file_character==EOF)
    				break;
    			
    			if(file_character=='.')
    			{
    				buffer[character]='\0';  
    				break;
    			}
    			
    			if(file_character=='?')
    			{
    				buffer[character]='\0';  
    				break;
    			}
    			
    			if(file_character=='!')
    			{
    				buffer[character]='\0';  
    				break;
    			}
    			
    			buffer[character]=file_character;
    		}
    		
    		if(file_character==EOF)
    			break;
    		fprintf(book2, "%s.\n", buffer);
    	}
    	fclose(book);
    	fclose(book2);
    	putchar('\n');
    	
    	return 0;
    }
     
    /* The function to find the first letter in the word */
    char find_letter (char* a, char* b)
    {
    	char string = strlen(b);
        strncpy (a,b,1);
        a[1]='\0';
        return 0;
    }
    
    /* The function to reverse the characters in a string */
    char* rev(char* str)
    {
    	int end= strlen(str)-1;
    	int start = 0;
    	
    	while( start<end )
    	{
    		char temp = str[ start ];
    		str[ start ] = str[ end ];
    		str[ end ] = temp;
    		
    		++start;
    		--end;
    	}
    	
    	return str;
    }
    
    /* The function for percentage calculation */
    void percentage_calculation_numbers(char* a_pch, char* a_b)
    {
    	FILE *fp;
        char str2[7];
        char vowels[] = "aeiouyAEIOUY";
        char letters[] = "bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXYZ";
        char alphabet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        float one;
        float two;
        float three;
        float four;
        float total;
        float five;
        float six;
        float seven;
        float eight;
        float total_2;
        float percentage_1;
        float percentage_2;
        float percentage_3;
        float percentage_4;
         
        one = 0;
        two = 0;
        three = 0;
        four = 0;
        total = 0;
        five = 0;
        six = 0;
        seven = 0;
        eight = 0;
        total_2 = 0;
        percentage_1 = 0;
        percentage_2 = 0;
        percentage_3 = 0;
        percentage_4 = 0;
    	
    	/* open text file or report error */
    	fp = fopen("writelist.txt", "a+");
      
        if(!fp) {printf("Error: unable to open input file!\n"); return 1;}
    
    	/* Displays the first letter of the sentence above the list made in the while loop
    	So in large articles you can find the sentence being counted.*/
    	printf("%s\n\n", a_pch);
        
    	/* The while loop gives value to five, six, seven, eight, which is used for the percentage calculation */
    	while(a_pch != NULL)
    	{
    		/* identify the first letter in the word begin */
              
            red = find_letter(str2, a_pch);
            
    		if(strpbrk(str2, letters))
            {
    			one++;
            }
            
    		if(strpbrk(str2, vowels))
            {
    			two++;
            }
            
    		/* identify the first letter in the word end */
    		
    		/* identify the last letter in the word begin */
            
    		reverse = rev(a_pch);
    		red = find_letter(str2, a_pch);
            
    		if(strpbrk(str2, letters))
            {
    			three++;
            }
            
    		if(strpbrk(str2, vowels))
            {
    			four++;
            }
            
    		/* identify the last letter in the word end */
    
            /* The math using the first and last letter begin */
    
    		/* pch is backwards, so I use rev to reverse it back */
    		/*printf("%s uncomment to test to see if the string is backwards", pch);*/
    		reverse = rev(a_pch);
    
    		/*The math using the first and last letter begin
    		Here I give the word a new string value, based on how the vowel is situated in the word.*/
    
            if(total = (one && three))
            {
    			five++;
    			printf("point\n");
    			fprintf(fp, "point\n");
            }
            
    		else if(total = (one && four))
            {
    			six++;
    			printf("shoot\n");
    			fprintf(fp, "shoot\n");
            }
            
    		else if(total = (two && three))
            {
    			seven++;
    			printf("reload\n");
    			fprintf(fp, "reload\n");
            }
            
    		else if(total = (two && four))
            {
    			eight++;
    			printf("autofire\n");
    			fprintf(fp, "autofire\n");
            }
            
    		/* The math using the first and last letter end */
      
            /* Reset the pointers */
    		
    		one = 0;
            two = 0;
            three = 0;
            four = 0;
            total = 0;
            
    		a_pch = strtok (NULL, " .");
    	}
    	/* Add separation between lines in console window, to identify sentence separation*/
    	putchar('\n');
    
    	/* pch is NULL, so I find alphabet in b and pass that into pch */
    	a_pch = strpbrk(a_b, alphabet);
    	
    	/* Count the pointers */
    	total_2 = (five + six + seven + eight);
    	percentage_1 = ((five)/ total_2);
    	percentage_2 = ((six)/ total_2);
    	percentage_3 = ((seven)/ total_2);
    	percentage_4 = ((eight)/ total_2);
    	
    	/* Display the results in the console window */
    	printf("letter vowel letter %f\nletter vowel vowel %f\nvowel vowel letter %f\nvowel vowel vowel %f\n\n", 
    		percentage_1, percentage_2, percentage_3, percentage_4);
            
       /* puts a period into the textfile after a sentence is processed
       This way I can count the number of periods in the text file */
        fprintf(fp, ".\n");
    		
    	fclose(fp);
    }
    
    /* function to find pattern, useful to identify how the words parallel a syllogism */
    int find_pattern(void)
    {
    	/* declare variable arrays */
    	int period = 0;
    	int one = 1;
    
    	char Darii[] = "reload\npoint\nshoot\npoint\nshoot\npoint\nautofire\npoint";
    	char Camestros[] = "reload\npoint\nshoot\npoint\nshoot\npoint\nshoot\npoint";
    	char Baroco[] = "reload\nautofire\npoint\nautofire\nreload\nshoot\npoint\nautofire\npoint\nreload";
    	char Bocardo[] = "shoot\npoint\nshoot\nshoot\npoint\nreload\npoint\nautofire\npoint";
    	char Celaront[] = "shoot\npoint\nshoot\npoint\nreload\npoint\nautofire\npoint";
    	char Felapton[] = "shoot\npoint\nautofire\nreload\nreload\npoint\nautofire\npoint";
    	char Ferio[] = "shoot\npoint\nreload\npoint\nshoot\npoint\nreload\npoint";
    	char Darapti[] = "reload\npoint\nautofire\npoint\nreload\npoint\nautofire\npoint";
        char buffer[LINES];
    	char pch[LINES] = {0};
    
    	/* Read the list made by the percentage function */
    
        FILE *book=fopen("writelist.txt", "r");
        if(!book) {printf("Error: unable to open input file!\n"); return 1;}
    	while(fgets(buffer, sizeof(buffer), book)!=NULL)
    	{
    		/* Find the word then add it the the pch string */
    		if (strstr(buffer, "point"))
    		{
    			strcat(pch, buffer);
    		}
    		if (strstr(buffer, "shoot"))
    		{
    			strcat(pch, buffer);
    		}
    		if (strstr(buffer, "reload"))
    		{
    			strcat(pch, buffer);
    		}
    		if (strstr(buffer, "autofire"))
    		{
    			strcat(pch, buffer);
    		}
    		
    		/* counting the periods in the input text file*/
    		if (strstr(buffer, "."))
    		{
    			period++;
    		}
            
            /* After two periods are counted the while loop is exited */
            if(period > one)
            {
                if(strstr(pch, Darii))
                {
                printf("Type Darii (AII-1) Syllogism pattern found\n\n");
                }
                else if(strstr(pch, Camestros))
                {
                printf("Type Camestros (AEO-2) Syllogism pattern found\n\n");
                }
                else if(strstr(pch, Baroco))
                {
                printf("Type Baroco (AOO-2) Syllogism pattern found\n\n");
                }
                else if(strstr(pch, Bocardo))
                {
                printf("Type Bocardo (OAO-3) Syllogism pattern found\n\n");
                }
                else if(strstr(pch, Celaront))
                {
                printf("Type Celaront (EAO-1)_or_Celarent (EAE-1) Syllogism pattern found\n\n");
                }
                else if(strstr(pch, Felapton))
                {
                printf("Type Felapton (EAO-3) Syllogism pattern found\n\n");
                }
                else if(strstr(pch, Ferio))
                {
                printf("Type Ferio (EIO-1) Syllogism pattern found\n\n");
                }
                else if(strstr(pch, Darapti))
                {
                printf("Type Darapti (AAI-3)_or_Barbari (AAI-1)_or_Barbara (AAA-1) Syllogism pattern found\n\n");
                }
                
                /* resetting the pch array to zero, so there is room to fill it again */
                
                if(period > one)
                {
                memset(&pch[0], 0, sizeof(pch));
                }
                period = 0;
            }
    	}
       fclose(book);
       
       /* Compare the pch string to the declared variable arrays */
    }
    
    /* function so I don't have to type getch all over the place */
    void MyExit(void) { system("pause"); }
       
    /* the main program */ 
    int main ()
    {   
    	/* declaring and initiaizing variables */
    	FILE *book;
    	char * pch = malloc(300);
    	char alphabet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	char buffer[LINES];
    
    	/* The function is called so I don't have to type getch */
    	atexit(MyExit);    
    	
    	/* The function is called and creates the text file */
    	split_by_sentence();
    	
    	/* The text file just created is opened */
    	book = fopen("readtext.txt", "r");
    	
    	if(!book)   
    	{
    		perror("Error: file readtext.txt was not found or opened");   
    		return 0;   
    	}
    	
    	/* read from file */
    	while(fgets(buffer, sizeof(buffer), book)!=NULL)
    	{ 
    		/* I tokenize the input string into individual words */
    		pch = strtok (buffer, " ~!@#$%^&*()_+`1234567890-=[]\'\"/;/|,./{}:<>?");
    		
    		/* I find the alphabet in pch after it's run through strtok */
    		if(strpbrk(pch, alphabet))
    		{
    			/* I run the percentage function which also creates the new terms for the words processed */
    			percentage_calculation_numbers(pch, buffer);
    		}
    	}
    		fclose(book);
    		find_pattern();
    		return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. count words
    By 74466 in forum C++ Programming
    Replies: 4
    Last Post: 02-17-2006, 09:30 AM
  2. words count
    By arlenagha in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2003, 09:29 AM
  3. how to count the number of sentences.
    By Ray Thompson in forum C Programming
    Replies: 3
    Last Post: 11-10-2002, 10:25 AM
  4. how to count sentences and words?
    By Ray Thompson in forum C Programming
    Replies: 1
    Last Post: 11-08-2002, 01:42 PM
  5. Replies: 2
    Last Post: 05-05-2002, 02:38 PM

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