hi all,
i can't do the programme in c++ "Write a scanf function in c which accept sentence from user."pls any body reply.

thank you in advance

Re: Write a scanf function in c which accept sentence from user. 80 80

First, I assume that a sentence or a line will end when the user presses enter after input.

#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    char s[100];
	scanf("%[^\n]",&s);
	printf("%s",s);
	return 0;
}

The use of scanf here is very useful , \^n means exclude ^n character ( or new line ). Hence, scanf will read every character and stops when it sees new line character, which is equivalent to pressing enter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.