ALL Parts of String
//Insert and print Charter,string,string sentence...
#include <stdio.h>
int main()
{
char ch,s[50],sen[500];
printf("Enter your Charter:");
scanf("%c",&ch);
printf("Enter string is:");
scanf("%s",s);
printf("Enter string sentence is:");
scanf("\n");
scanf("%[^\n]%*c",sen);
printf("The charter is: %c\n",ch);
printf("The string is: %s\n",s);
printf("The sentence is: %s",sen);
return 0;
}
// String counter in c++
#include<iostream>
using namespace std;
int main()
{
char s[34]; //charter array is one kind of string.........
cin>>s;
int count=0;
for(int i=0;s[i]!='\0';++i) //string last part is '\0'
{
count++; //enter in the loop and increase count 1+
}
cout<<count;
return 0;
}
//String reverse in c++
#include<iostream>
using namespace std;
int main()
{
char s[12],r[12]; //charter array is one kind of string.........
cout<< "Enter your String: ";
cin>>s;
int begin,end,count=0;
for(int i=0;s[i]!='\0';++i) //string last part is '\0'
{
count++; //enter in the loop and increase count 1+
}
end=count-1;
for(begin=0;begin<count;begin++)
{
r[begin]=s[end];
end--;
}
r[begin]='\0'; //set '\0' at last
cout<<"Reverse string: ";
cout<<r;
}
#include <stdio.h>
int main()
{
char ch,s[50],sen[500];
printf("Enter your Charter:");
scanf("%c",&ch);
printf("Enter string is:");
scanf("%s",s);
printf("Enter string sentence is:");
scanf("\n");
scanf("%[^\n]%*c",sen);
printf("The charter is: %c\n",ch);
printf("The string is: %s\n",s);
printf("The sentence is: %s",sen);
return 0;
}
// String counter in c++
#include<iostream>
using namespace std;
int main()
{
char s[34]; //charter array is one kind of string.........
cin>>s;
int count=0;
for(int i=0;s[i]!='\0';++i) //string last part is '\0'
{
count++; //enter in the loop and increase count 1+
}
cout<<count;
return 0;
}
//String reverse in c++
#include<iostream>
using namespace std;
int main()
{
char s[12],r[12]; //charter array is one kind of string.........
cout<< "Enter your String: ";
cin>>s;
int begin,end,count=0;
for(int i=0;s[i]!='\0';++i) //string last part is '\0'
{
count++; //enter in the loop and increase count 1+
}
end=count-1;
for(begin=0;begin<count;begin++)
{
r[begin]=s[end];
end--;
}
r[begin]='\0'; //set '\0' at last
cout<<"Reverse string: ";
cout<<r;
}
//String split in c
#include <stdio.h>
#include <string.h>
int main()
{
char str[] = "Monju The Super Star";
printf("The given string is: ");
puts(str); //just print string .........
int init_size = strlen(str);
char search[] = " ";
char *ptr = strtok(str, search); //pointer to point the array where found space
printf("\nAfter string split:\n");
while(ptr != NULL)
{
printf("'%s'\n", ptr);
ptr = strtok(NULL, search);
}
/* This loop will show that there are zeroes in the str after tokenizing */
for (int i = 0; i < init_size; i++)
{
printf("%d ", str[i]); /* Convert the character to integer, in this case
the character's ASCII equivalent */
}
printf("\n");
return 0;
}
No comments