Question:

C Programming - 2D array to lowercase?

by  |  earlier

0 LIKES UnLike

Hi everybody,

I was just wondering if there was another way of going through a 2D array without a for loop and converting every element to lowercase letters with tolower().

If anyone knows of a way, can I get an explanation on how that could work?

Thanks.

 Tags:

   Report

3 ANSWERS


  1. I think Ajay is right,cause recursion is  alternate to for & while loops.

    Though it is a little bit troublesome.


  2. Leave the array as it is and only do the conversion when you read an element or alternatively when you load the array do the conversion.  

  3. Hi matt d

    Suppose your 2D array is this: myArray[ROWS][COLS], whose elements you wish to convert to lowercase. If you don't want to use a for loop, you can use another loop, such as while loop, thus:

    int row=ROWS, col=COLS;

    while (row--)

        while (col--)

            myArray[row][col]=tolower (myArray[row][col]);

    But if you just don't want to use any loop, then you can use recursion. Make a function that takes address of a character in the array, its row no., and its column no. as inputs, converts the case of the character at the given position, and then calls itself repeatedly each time incrementing the value of its 3rd parameter. There are two more things you need to do in this function: One--Every time a column of any row has been fully traversed, increment the row (the 2nd parameter). Two--When the entire array has been traversed, stop calling, just return.

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions