answersLogoWhite

0


Best Answer

#include
#include

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::getline;

int main()
{
string myStr = "";
cout << endl << "Enter your line (to finish press #): ";
getline(cin, myStr, '#');

cout << endl << "You have entered: "" << myStr << """
<< endl;

system("PAUSE");
return 0;

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write c program to enter a string it has to display with space?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a C program to accept a string from user and display its ascii value and then display sum of all ascii value of strings?

//C program to accept a string from user and //display its ascii value and //then display sum of all ascii value of strings #include&lt;stdio.h&gt; #include &lt;string.h&gt; int main() { char String[100]; int Sum,Index; Sum=0; //Sum is initially zero printf("Enter the string:\n"); gets(String); //Accept String from User for(Index=0;Index&lt;strlen(String);Index++) { Sum+=(String[Index]); //Adds (the ASCII values of) the String characters. } printf("The sum is %d\n",Sum); //Printing it as %d gives the equivalent ASCII value. return 0; }


Write a c program using string concept enter a sting and replace the new string in to old string and find no of occurrence?

print c co com comp compu


How do you write a c program to prints name?

Write a c program that reads your first name and surname when you enter them. Each part of your name should not be more than 12 characters. Finally, have the program display your full name.


Java program to give input of a string and display it?

import java.util.*; public class Example { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please enter a string:"); String input = in.next(); System.out.println("The String you entered is: " + input); } }


How do you write a program that asks the user to enter their favouite tv programme and display the result 15 times?

#include &lt;iostream&gt; #include &lt;string&gt; using std::cin; using std::cout; using std::endl; using std::string; int main() { cout &lt;&lt; "Enter name of your favorite TV show: \n"; string tvShow = ""; cin &gt;&gt; tvShow; for (int i = 0; i &lt; 15; i++) { cout &lt;&lt; endl &lt;&lt; tvShow; } cout &lt;&lt; endl &lt;&lt; endl; system("PAUSE"); return 0; }

Related questions

Write a C program to accept a string from user and display its ascii value and then display sum of all ascii value of strings?

//C program to accept a string from user and //display its ascii value and //then display sum of all ascii value of strings #include&lt;stdio.h&gt; #include &lt;string.h&gt; int main() { char String[100]; int Sum,Index; Sum=0; //Sum is initially zero printf("Enter the string:\n"); gets(String); //Accept String from User for(Index=0;Index&lt;strlen(String);Index++) { Sum+=(String[Index]); //Adds (the ASCII values of) the String characters. } printf("The sum is %d\n",Sum); //Printing it as %d gives the equivalent ASCII value. return 0; }


Write a c program using string concept enter a sting and replace the new string in to old string and find no of occurrence?

print c co com comp compu


How do you display a text reversely in C language without using onlu simply input and output?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { char string[20]; int i=0; printf("Enter the string.\n"); while(i&lt;=19) { scanf("%c",&amp;string[i]); i++; } while(i&gt;=0) { printf("%c",string[i]); i--; } getch(); } In this program it is compulsory to enter 20 characters. Now we can write a program in which it is not necessary. #include&lt;stdio.h&gt; #include&lt;conio.h&gt; #include&lt;string.h&gt; void main() { char string[20]; int length; printf("enter the string.\n"); gets(string); length=strlen(string); length--; while(length&gt;0) { printf("%c",string[length]); length--; } getch(); }


Write a program that converts a string from small letters to capital letters and vice versa?

Here's a Python program that accomplishes this: def convert_case(input_str): return input_str.swapcase() user_input = input(&quot;Enter a string: &quot;) converted_str = convert_case(user_input) print(&quot;Converted string:&quot;, converted_str)


How do you write a c program to prints name?

Write a c program that reads your first name and surname when you enter them. Each part of your name should not be more than 12 characters. Finally, have the program display your full name.


Java program to give input of a string and display it?

import java.util.*; public class Example { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please enter a string:"); String input = in.next(); System.out.println("The String you entered is: " + input); } }


How do you write a program that asks the user to enter their favouite tv programme and display the result 15 times?

#include &lt;iostream&gt; #include &lt;string&gt; using std::cin; using std::cout; using std::endl; using std::string; int main() { cout &lt;&lt; "Enter name of your favorite TV show: \n"; string tvShow = ""; cin &gt;&gt; tvShow; for (int i = 0; i &lt; 15; i++) { cout &lt;&lt; endl &lt;&lt; tvShow; } cout &lt;&lt; endl &lt;&lt; endl; system("PAUSE"); return 0; }


Write a c plus plus program to read a line from keyboard?

#include &lt;iostream&gt; #include &lt;string&gt; int main() { std::string myStr = ""; std::cout &lt;&lt; std::endl &lt;&lt; "Enter a string: "; std::cin &gt;&gt; myStr; system("PAUSE"); return 0; }


Write a program in java to enter 3 digits or more arrange the digits of the entered number in ascending order and display the result?

public static void main(String[] args) { int val = 100; int val1 = 50; System.out.println("Number of digits in " + val + " is: " + new String(val + "").length()); System.out.println("Number of digits in " + val1 + " is: " + new String(val1 + "").length()); }


Write a program to accept two string and display weather they are identical or not?

I assume the program should be case-sensitive. Here is a code of such program:#include #include int main() {char str1[100];char str2[100];printf("Please enter first string: ");gets(str1);printf("Please enter second string: ");gets(str2);if (strcmp(str1, str2) == 0) {printf("Strings are Equal.\n");} else {printf("Strings are Not Equal.\n");}return 0;}Testing:Please enter first string: APlease enter second string: AStrings are Equal.Please enter first string: aPlease enter second string: AStrings are Not Equal.If you want to make not case-sensitive comparing before checking you should make both string in lowercase or uppercase.Here is how it should look:#include #include #include void upString(char *str);int main() {char str1[100];char str2[100];printf("Please enter first string: ");gets(str1);printf("Please enter second string: ");gets(str2);upString(str1);upString(str2);if (strcmp(str1, str2) == 0) {printf("Strings are Equal.\n");} else {printf("Strings are Not Equal.\n");}return 0;}void upString(char *str) {register int ind = 0;while (str[ind]) {str[ind] = toupper(str[ind]);ind++;}}Testing:Please enter first string: aaaPlease enter second string: AAAStrings are Equal.Please enter first string: aaaPlease enter second string: aAaStrings are Equal.Note: You should not be using gets() function in real-world application. There is no way you can limit number of characters to read thus allowing to overflow buffer. It was used only for example.


Write a program that will accept two numbers and find their sum anddifferences. If the sum is more than the difference, display the sum otherwisedisplay the difference. Pascal programming?

program SumAndDifference; var num1, num2, sum, difference: integer; begin write('Enter first number: '); read(num1); write('Enter second number: '); read(num2); sum := num1 + num2; difference := num1 - num2; if sum &gt; difference then written('The sum is greater: ', sum) else written('The difference is greater: ', difference); end. This program will prompt the user to enter two numbers, calculate their sum and difference, and then compare the two values. If the sum is greater than the difference, it will display the sum; otherwise, it will display the difference.


Write a program to accept a string from keyboard and count and display the numbers of vowels present in the string by using function?

You need to scan through the string and keep track of the vowelsoccurring. Here is a sample program:#include#includeint countVowels(char[] s){int count = 0, i;for( i=0; char[i] != '\0'; i++){switch(char[i]){case 'a':case 'e':case 'i':case 'u':case 'o': count++;break;}}return count;}int main(){char str[256];printf("Enter the string:\t");scanf("%s", str);printf("The number of vowels in the string are :%d\n", countVowels(str));return 0;}