answersLogoWhite

0

Can you use scanf to get a string to a c program?

Updated: 8/20/2019
User Avatar

Wiki User

12y ago

Best Answer

Certainly. That's what sequence %s is good for.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you use scanf to get a string to a c program?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How can we read two strings using c program?

#include,stdio.h>main(){char string1[20],string2[20]printf("enter the first string");scanf("%s",string1);// reading the string1printf("enter the second string");scanf("%s", string2);// reading the the string2printf( "the first string is %s",string1);// printing the string1printf("the second string is %s",string2);// printing the string2}the problem of using scanf is that it does not take space. so we can use gets for it.ie instead of scanf("%s",string1); we can use gets(string1); .


What is the use of Reverse String in C program?

The use of the reverse string in C program is used to reverse the letters in the string. An example would be reverse me would be reversed to em esrever.


C program to accept a sentence using scanf?

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


Can you use getchar instead of scanf in a c program?

They do different things, read the manual/help for details.


Program to find the size of the string in c?

int main (void) { char buf[1024]; scanf ("Enter a string: %s", buf); printf ("The length of the string is %d chars long.\n", strlen (buf)); return 0; }


C program to receive floating point and convert it into binary?

scanf


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

#include<stdio.h> #include<conio.h> void main() { char string[20]; int i=0; printf("Enter the string.\n"); while(i<=19) { scanf("%c",&string[i]); i++; } while(i>=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<stdio.h> #include<conio.h> #include<string.h> void main() { char string[20]; int length; printf("enter the string.\n"); gets(string); length=strlen(string); length--; while(length>0) { printf("%c",string[length]); length--; } getch(); }


Write a c program to count the number of word in a string?

#include<stdio.h> void main() { int cnt=0,i; char str[100]; printf("Enter the string "); scanf("%s",str); for(i=0;i<strlen(str)-1;i++) { if(str[i]==' ') cnt++; } printf("\nTotal no. of word in string = %d",cnt); }


What is difference between scanf and cin?

scanf is a function (available in C and C++)cin is an istream object (C++ only)Advice: when in doubt, use fgets+sscanf


How you get the size of arrays from user?

in c simply add three lines in the begining of your program: int x; printf("enter the size of the array to be entered :"); scanf("%d",&x); after that use x as your maximum limit of array in your program. in c++ just replace above printf & scanf statements by cout<<"enter the size of the array to be entered :"; & cin>>x; respectively and do not use brackets.


Scanf function in c for strings?

Use '%s', eg: char name[64]; scanf ("%s", name);


Why do you use scanf in c?

To read input from standard input.