So i have a program to convert all of the capital letters into smaller ones.
#include <stdio.h>
#include <stdlib.h>
char v2m(char z)
{
if(z >= 'A' && z <= 'Z')
return z += 32;
else return z;
}
void convert(char ** array, int n)
{
for(int i = 0; i < n; i++)
for(int j = 0; (* (array + i))[j] != '\0'; j++)
(* (array + i))[j] = v2m((* (array + i))[j]);
}
int main()
{
char * strings[5] = { "Pen", "Car", "Dev", "Lamp", "Noon" };
printf("Before: ");
for(int i = 0; i < 5; i++)
printf("\n%s", * (strings + i));
convert(strings, 5);
printf("\nAfter: ");
for(int i = 0; i < 5; i++)
printf("\n%s", * (strings + i));
return 0;
}
I know that the problem lies in the fact that i can't change the content of pointer arrays and would like to know is there a simpler way that I can declare and initialize array strings without user input. Mainly to modify this part of code.
char * strings[5] = { "Pen", "Car", "Dev", "Lamp", "Noon" };