Thread: character range

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    41

    character range

    How can i store all the character within the range that i had stated in a string ??

    eg like if i enter a-j, it will store abcdefghij in the string.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    char alpha[] = "abc";
    search the array until you find the start letter
    copy the letters until you find the end letter
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    41
    What this code does is it passes the character range to the validateString function, eg a-e. But currently i have problem storing back the character into the string array. How can i solve this problem ???

    Code:
    int validateString(char *sC, char *rC)
    {
    
    char* tempArray = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    int start;
    int end; 
    int boolcounter = 0;
    char temp[30];
    int i=0;
    
    start = *rC;
    rC++;
    rC++;
    end = *rC;	
    	while (*tempArray != end + 1)
    	{
    		if(*tempArray == start)
    		{
    				boolcounter = 1;
    		}
    		if(boolcounter == 1){
    		temp[i++] = *tempArray; // PROBLEM
    
    		}
    		tempArray++;
    
    	}
    
    	return 1;
    
    }

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I suggest you pass temp as a parameter to the function.
    void func ( char *buffer, char start, char end )

    Don't forget to add a \0 to the end of any string you create.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  3. get wide character and multibyte character value
    By George2 in forum C++ Programming
    Replies: 27
    Last Post: 01-27-2008, 05:10 AM
  4. Problem with loop stopping at wrong time
    By Baron in forum C Programming
    Replies: 11
    Last Post: 12-14-2005, 08:35 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM