L6_T2

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
904 B
2
Indexable
Never
#include <iostream>
#include <string>

using namespace std;

int StrLength(char*);
void StrReverse(char*);
void StrComaLeftShift(char*);

int main() {
	const int STR_LEN = 25;

	char* str = new char[STR_LEN];

	cout << "Input string: " << endl;
	cin.getline(str, STR_LEN);

	StrComaLeftShift(str);
	cout << str << endl;

	// ghgh, shdfhshf, sjafldasdf, dsjfakl

	return 0;
}

int StrLength(char *str) {
	int len;
	for (len = 0; str[len] != '\0'; len++);
	return len;
}
void StrComaLeftShift(char *str) {
	int len = StrLength(str);
	int firstComaIndex = -1, lastComaIndex = 0;

	//find coma indiсes
	for(int i = 0; str[i] != '\0'; i++) 
	{
		if (str[i] == ',') {
			if (firstComaIndex == -1)
				firstComaIndex = i;
			lastComaIndex = i;
		}
	}
	for (int i = firstComaIndex; i < lastComaIndex; i++) 
	{
	    for(int j = firstComaIndex; j < len; j++)
	    {
	        str[j] = str[j + 1];
	    }	    
	}
}