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

What is the size of enum in bytes?

0 Answers  


How can a program be made to print the line number where an error occurs?

0 Answers  


What is line in c preprocessor?

0 Answers  


what is c language.

3 Answers  


#include<stdio.h> main() { char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1); } Find the output

5 Answers   CitiGroup,






What is volatile keyword in c?

0 Answers  


what do you mean by enumeration constant?

0 Answers  


You are given a string which contains some special characters. You also have set of special characters. You are given other string (call it as pattern string). Your job is to write a program to replace each special characters in given string by pattern string. You are not allowed to create new resulting string. You need to allocate some new memory to given existing string but constraint is you can only allocate memory one time. Allocate memory exactly what you need not more not less.

2 Answers   Microsoft,


write a c program to change only the 3rd bit of the particular number such that other bits are not affected.. if bitnum=10(say.. it can be any no..

10 Answers   Bosch, Mind Tree,


What are the 4 types of organizational structures?

0 Answers  


will the program compile? int i; scanf(ā€œ%dā€,i); printf(ā€œ%dā€,i);

3 Answers  


m=++i&&++j(||)k++ printf("%d"i,j,k,m)

1 Answers   ABC,


Categories