Home > Backend Development > C#.Net Tutorial > How to use scanf to input string in C language

How to use scanf to input string in C language

王林
Release: 2020-05-09 10:36:40
Original
10894 people have browsed it

How to use scanf to input string in C language

1. There is no string type in C language, and there is no string variable. Strings are implemented as character arrays.

2. The array name is the address of the first element of the array.

3. scanf("",x); The second parameter should be the address, but for character arrays, & can be used or not.

Specific code:

#include <stdio.h>
int main()
{
    char a[26],b[10];
    scanf("%s%s", a,&b);
    printf("a=%s,b=%s", a, b);
    system("pause");
    return 0;
}
Copy after login

Result:

输入: abc 123
输出:a=abc , b=123
Copy after login

Recommended tutorial: c language tutorial

The above is the detailed content of How to use scanf to input string in C language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template