Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,821 answers

573 users

How to extract the first letter from each word in a string with C++

2 Answers

0 votes
#include <iostream>

using namespace std;

void get_first_letters(char *s, char *fl);

int main()
{
	char s[] = "c++ programming language";
	char fl[10] = "";

	get_first_letters(s, fl);

	cout << fl << endl;

	return 0;
}
void get_first_letters(char *s, char *fl)
{
	if (s == NULL) return;

	int len = strlen(s);

	if (s[0] != ' ' && s[0] != '\0') fl[0] = s[0];

	for (int i = 1, j = 1; i < len; i++)
	{
		if (s[i] == ' ')
			fl[j++] = s[i + 1];
	}
}


/*
run:

cpl

*/

 



answered Jan 28, 2017 by avibootz
0 votes
#include <iostream>

using namespace std;

void get_first_letters(char *s, char *fl);

int main()
{
	char s[] = "c++ programming language";
	char fl[10] = "";

	get_first_letters(s, fl);

	cout << fl << endl;

	return 0;
}
void get_first_letters(char *s, char *fl)
{
	if (s == NULL) return;

	int len = strlen(s);

	if (s[0] != ' ' && s[0] != '\0') fl[0] = s[0];

	for (int i = 1, j = 1; i < len; i++)
	{
		if (s[i] == ' ')
		{
			if (i + 1 < len && s[i + 1] != ' ')
				fl[j++] = s[i + 1];
		}
	}
}


/*
run:

cpl

*/

 



answered Jan 28, 2017 by avibootz

Related questions

...