How to receive strings with spaces in scanf()

Answers were Sorted based on User's Feedback



How to receive strings with spaces in scanf()..

Answer / valli

char a[50];
use scanf(" %[^\n]",a);

Is This Answer Correct ?    10 Yes 2 No

How to receive strings with spaces in scanf()..

Answer / rushabh

scanf("[^\n]s",s);

Is This Answer Correct ?    5 Yes 2 No

How to receive strings with spaces in scanf()..

Answer / vignesh1988i

#include<stdio.h>
#include<conio.h>
void main()
{
char a[50];
printf("enter the string :");
for(int i=0;1;i++)
{
scanf("%c",&a[i]);
if(a[i]=='\n')
a[i]='\0'
break;
}
for(i=0;a[i]!='\0;i++)
printf("%c",a[i]);
getch();
}

Is This Answer Correct ?    4 Yes 3 No

How to receive strings with spaces in scanf()..

Answer / suman halder

#include<stdio.h>
int main()
{
char str[100];
scanf("%[^\n]s",str);

}

Is This Answer Correct ?    2 Yes 1 No

How to receive strings with spaces in scanf()..

Answer / murugannr

#include<studio.>
#include<coino.>
viod main
{
int a,b:
char a[12];
char b[10];
Printf{"enter the using string a,b");
scanf("%s,%a,%b");
get(ab)
}

Is This Answer Correct ?    0 Yes 0 No

How to receive strings with spaces in scanf()..

Answer / karthik

using the function
gets(variable)

Is This Answer Correct ?    2 Yes 7 No

How to receive strings with spaces in scanf()..

Answer / parmjeet kumar

#include<stdio.h>
#include<conio.h>
void main()
{
char a[50];
printf("enter the string:");
scanf("%s",&a);
printf("%s",a);
getch();
}

Is This Answer Correct ?    0 Yes 10 No

Post New Answer

More C Interview Questions

Can anyone tell what is stack overflow? what precaution we should take?

1 Answers  


Write an algorithm for a program that receives an integer as input and outputs the product of of its digits. E.g. 1234 = 24, 705 = 0

4 Answers  


program to find middle element of linklist?

1 Answers   Huawei,


1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

3 Answers  


How do you do dynamic memory allocation in C applications?

0 Answers  


Which of the following are valid "include" formats? A)#include and #include[file.h] B)#include (file.h) and #include C)#include [file.h] and #include "file.h" D)#include <file.h> and #include "file.h"

15 Answers   Accenture,


Why does the call char scanf work?

0 Answers  


how memory store byte

4 Answers   Huawei,


program to print upper & lower triangle of a matrix

2 Answers   TCS,


write a c program to find the sum of five entered numbers using an array named number

0 Answers   TATA,


what is the use of getch() function in C program.. difference b/w getch() and getche()??

29 Answers   HCL, IBM, Infosys, TCS, Wipro,


Write one statement equalent to the following two statements x=sqr(a); return(x); Choose from one of the alternatives a.return(sqr(a)); b.printf("sqr(a)"); c.return(a*a*a); d.printf("%d",sqr(a));

6 Answers   TCS,


Categories