0

I want to print each first character of a List of Array in upper case using C.

For example, if I have Array of these elements

char *d[] = {"water", "salt", "sugar", "milk", "soda"};

I want my function to print them like this

Water Salt Sugar Milk Soda

I will appreciate any help.


Thank

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by arafat_alam
0

Start by writing some code that outputs each word.

Then change the code to add capitalization.

0

1

[edit] If you're going to remove a message, leave a useful message in it's place. Like "Duplicate removed". [/edit]

Edited by WaltP: duplicated -- Bad message

-1

bellow i tried to solve your problem bt the problem i m facing that i cant count the number of words in the array ..so i passed the number manually in line 10..if you can solve it pls inform

//Pirate™
#include<stdio.h>
#include<stdlib.h>

void print_words(char *str[],int m);

void main()
{
        char *d[]={"water","salt","suger","milk","soda"};
	print_words(d,5);
}

void print_words(char *str[],int m)
{
	char *temp;
	
for(int i=0;i<m;i++)
	{
		int j=0;
	
		temp=str[i];

		while(*temp)
		{
			if(j==0)
				printf("%c",toupper(*temp));
			else
				printf("%c",*temp);
			j++;
			temp++;
			
		}
		printf(" ");
		
	}
	
}

Edited by arafat_alam: n/a

Votes + Comments
Do NOT try to solve problems for people here. Help them solve the problems themselves
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.