Thread: simple text analyzsis program

  1. #1
    Registered User
    Join Date
    Sep 2008
    Location
    Jakarta
    Posts
    18

    simple text analyzsis program

    basically, this program will ask the user to write a line of text, and analyze the character in that line of text if its exist or not.
    ex :
    Code:
    enter line of text : abra kadabra
    'a' was found
    'b' was found
    'c' was not found
    .
    .
    .
    .
    but i have problems with my code, can someone please point out my mistakes.

    so, i use array to store the characters, but having problems using them.
    this is my code so far :

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    #define MAXLINE 50
    
    int main (void)
    {
    
    	char string[MAXLINE];
    	char *alphabet[26] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
    	int i;
    	
    	
    	printf ( "Please enter a line of text ( maximum %d characters ) :", sizeof(string) );
    	fgets (string, sizeof(string), stdin);
    	
    	for ( i=0; i <=20 ; i++) {
    	
    		if ( strchr ( string, alphabet[i] ) != NULL ) {
    			printf("\'%c\' was found in \"%s\".\n", alphabet[i], string );
    		}
    			else {
    				printf ("\'%c\' was not found in \"%s\".\n", alphabet[i], string);
    				
    			}
    		
    	}
    		getchar();
    		return 0;
    		}

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    strchr searches for a single character, not a string. Therefore alphabet should not be an array of strings but just a single string.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Jakarta
    Posts
    18
    i'm not really sure how to do it... let me try it...

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Jakarta
    Posts
    18
    wow ! it worked ! thx mate !

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    Smile

    This post was very helpful to me, thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 19
    Last Post: 05-30-2007, 05:47 PM
  2. simple frontend program problem
    By gandalf_bar in forum Linux Programming
    Replies: 16
    Last Post: 04-22-2004, 06:33 AM
  3. Simple Text manipulation program
    By phlavio in forum C++ Programming
    Replies: 4
    Last Post: 03-03-2003, 12:35 PM
  4. Replies: 5
    Last Post: 02-01-2003, 10:58 AM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM