Manipulating Strings? (tolower, toupper, ucfirst)

This is a discussion on Manipulating Strings? (tolower, toupper, ucfirst) within the C Programming forums, part of the General Programming Boards category; Hello all! I'm interested in creating a function that will take in an array and, using pointers, change that array ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    11

    Manipulating Strings? (tolower, toupper, ucfirst)

    Hello all!

    I'm interested in creating a function that will take in an array and, using pointers, change that array to all lowercase. The process will be replicated in 2 other functions to change all of the array to uppercase letters or just the first letter of each word capitalized.

    What I have is as follows:
    Code:
    int strtolower(char theString[]){
    	int theLength = strlen(theString);
    	for (i=0;i<theLength;i++)
    		theString[i] = toupper(theString[i]);
    	
    	return 1;
    }
    However, my program stops unexpectedly when calling the function using:
    Code:
    char someArray[50][50][50];
    
    strtolower(someArray[0][0]);

    Any suggestions as to why my program is not performing as expected? Thanks for any help you can give!

  2. #2
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    983
    First off, you're not allowed to name your function strtolower (names beginning with str are reserved). But that's probably not your problem.

    someArray contains no string. It's just a declaration of an array, but it contains junk (unless it's global). You need to copy a string somewhere into it first.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    11
    thanks for the insight about str,i I wasn't aware of that!

    However, the code I presented was just an example of the usage. In my actual usage there are values in the array. How can I make this work if there aren't values? If there are?

    Thanks for the speedy response!

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    4
    Well then to get help you should post more code.

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    11
    Ok so the problem isn't in the function then? That's all I needed to know I guess...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. toupper() & tolower() problem?
    By saqib_ in forum C++ Programming
    Replies: 35
    Last Post: 12-04-2009, 10:45 AM
  2. Manipulating C strings
    By black_spot1984 in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2008, 10:23 AM
  3. Need help with toupper and tolower function
    By phoebus in forum C Programming
    Replies: 8
    Last Post: 04-27-2008, 10:18 PM
  4. manipulating strings
    By student2005 in forum C++ Programming
    Replies: 5
    Last Post: 01-08-2004, 02:21 AM
  5. toupper(); tolower(); ?
    By dune911 in forum C Programming
    Replies: 9
    Last Post: 01-07-2003, 05:40 PM

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