string
- A string of length n, where n+1 bits are
\0
char site[7] = {'T','i','a','n','J','i','n'};
char site[] = 'Tianjin';
printf("%s", site);
function
#include<stdio.h>
#include<string.h>
strcpy(str1,str2); // 复制str2到str1
strcat(str1,str2); // 连接str2到str1
strlen(str1); // 返回str1长度
strcmp(str1,str2); // 值相等返回0, 大于返回1, 小于返回-1
strchr(str1,ch); // 返回指针, 指向字符ch首次出现的位置
strstr(str1,st); // 返回指针, 指向字符串st首次出现的位置
character position strchr()
char *pr1 = "Tian";
char pr2 = 'a';
char *pt = strchr(pr1,pr2);
printf("%c",*pt);
output a
, of typechar*
String position strstr()
char *pr1 = "Tian";
char *pr2 = "ian";
char *pt = strstr(pr1,pr2);
printf("%c",*pt);
output i
, of typechar*
input Output
standard document
The C language treats all devices as files, devices are handled in the same way as files, the following files are automatically opened during program execution to access the keyboard & screen.
standard document | file pointer | equipment |
---|---|---|
standard input | stdin | keyboard |
stdout | stdout | Screen |
standard error | stderr | your screen |
stdio.h : standard input and output files |
enter
getchar()
: read the next available character from the screen, returning an integerint getchar(void)
gets()
: Read a line from stdin to the buffer pointed to by s, until a terminator /EOFchar *gets(char *s)
scanf()
: Read input from the standard input stream stdin, browse the input according to the provided formatint scanf(const char *formate, ...)
output
putchar()
: output characters to the screen, return the same character, output only a single character at the same timeint putchar(int c)
puts()
: write the string s and a trailing newline to stdoutint puts(const char *s)
printf()
: The output is written to the standard output stream stdout, and the output is generated by the formatint printf(const char *format)
scanf("%s %d",str,&sst);