character range

This is a discussion on character range within the C Programming forums, part of the General Programming Boards category; How can i store all the character within the range that i had stated in a string ?? eg like ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 04:10 AM
  4. Problem with loop stopping at wrong time
    By Baron in forum C Programming
    Replies: 11
    Last Post: 12-14-2005, 07:35 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM

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