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

王林
王林Original
2020-05-09 10:36:4010904browse

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;
}

Result:

输入: abc 123
输出:a=abc , b=123

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!

Statement:
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