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

Explain the use of keyword 'register' with respect to variables.

0 Answers  


general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only

0 Answers  


write a program to create a sparse matrix using dynamic memory allocation.

0 Answers  


What is sizeof return in c?

0 Answers  


i have to apply for the rbi for the post of officers. i need to know abt the entrance questions whether it may be aps or techinical....

0 Answers   RBI,






What is #define used for in c?

0 Answers  


what is array?

63 Answers   Amdocs, HCL,


Why functions are used in c?

0 Answers  


what is the flow of execution in cprogram? ex:printf();,scanf();

2 Answers  


char S; char S[6]= " HELLO"; printf("%s ",S[6]); output of the above program ? (0, ASCII 0, I,unpredictable)

7 Answers   Mascot,


Is array a primitive data type in c?

0 Answers  


What is #pragma statements?

0 Answers  


Categories