0% found this document useful (0 votes)
54 views4 pages

Tema Siruri

The document contains 5 code snippets in C++ that perform various string manipulation tasks like counting vowels, extracting first letters of words, and rearranging substrings. The snippets take a string as input, manipulate it using string functions like strchr, strcpy, strtok, and print outputs like modified strings, counts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views4 pages

Tema Siruri

The document contains 5 code snippets in C++ that perform various string manipulation tasks like counting vowels, extracting first letters of words, and rearranging substrings. The snippets take a string as input, manipulate it using string functions like strchr, strcpy, strtok, and print outputs like modified strings, counts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

Pb1)

#include <iostream>
#include <string.h>
using namespace std;

int main()
{
char txt[256],*p;

int nr1=1,poz,nr2=0;

cin.getline(txt,256);

if(txt[0]=='a'||txt[0]=='e'||txt[0]=='i'||txt[0]=='o'||txt[0]=='u')nr2++;

p=strchr(txt,' ');

while(p!=NULL){

poz=p-txt;
strcpy(txt,txt+poz+1);
if(txt[0]=='a'||txt[0]=='e'||txt[0]=='i'||txt[0]=='o'||txt[0]=='u')nr2++;
nr1++;
p=strchr(txt,' ');

cout<<nr1<<" "<<nr2;

return 0;
}

Pb2)

#include <iostream>
#include <string.h>
using namespace std;

int main()
{
char txt[101],txtt[101],*p;

int nr=1,poz,i=1;

cin.getline(txt,256);
p=strchr(txt,' ');
txtt[0]=txt[0];
while(p!=NULL){

poz=p-txt;
strcpy(txt,txt+1+poz);
txtt[i]=txt[0];
i++;
nr++;
p=strchr(txt,' ');

}
cout<<txtt<<" "<<nr;

Pb3)
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
char txt[101],txtt[101],*p;

int nr=1,poz,i=1;

cin.getline(txt,256);

p=strchr(txt,' ');
txtt[0]=txt[0];
while(p!=NULL){

poz=p-txt;
strcpy(txt,txt+1+poz);
txtt[i]=txt[0];
i++;
nr++;
p=strchr(txt,' ');

}
cout<<txtt<<" "<<nr;

Pb4)

#include <iostream>
#include <string.h>
using namespace std;

int main()
{
char txt[101],txtt[101],*p;

int poz,poz1=0,p1,p2,i,j=0,nr=0,nrmax=0;

cin.getline(txt,256);

p=strtok(txt," ");

while(p!=NULL){
nr=0;
poz=p-txt;

for(i=poz1;i<=poz;i++){
nr++;
}
if(nr>=nrmax){
nrmax=nr;
p1=poz1;
p2=poz;
}

poz1=poz;
p=strtok(NULL," ");

}
for(i=p1;i<=p2;i++){
txtt[j]=txt[i];
j++;
}

cout<<txtt;

return 0;
}

Pb5)

#include <iostream>
#include <string.h>

using namespace std;

int main()
{
char txt[100];
cin.getline(txt, 100);
char* x = strtok(txt, " ");
char* y = strtok(NULL, " ");

strcat(y, " ");


strcat(y, x);
strcpy(txt, y);

cout << txt;

return 0;
}

You might also like