It is used to reverse the given string expression.
1 2 3 4 5 6 7 8 9 10 11
#include<stdio.h>
int main() { char s1[50]; printf("Enter your string: "); gets(s1); printf("\nYour reverse string is: %s",strrev(s1)); return(0); }
1 2 3
// output Enter your string: studytonight Your reverse string is: thginotyduts
C语言: scanf输出输出一行包括空格的字符串
String Input and Output
Input function scanf() can be used with %s format specifier to read a string input from the terminal. But there is one problem with scanf() function, it terminates its input on the first white space it encounters. Therefore if you try to read an input string “Hello World” using scanf() function, it will only read Hello and terminate after encountering white spaces.
However, C supports a format specification known as the edit set conversion code %[..] that can be used to read a line containing a variety of characters, including white spaces.
1 2 3 4 5 6 7 8 9 10
#include<stdio.h> #include<string.h>
voidmain() { char str[20]; printf("Enter a string"); scanf("%[^\n]", &str); //scanning the whole string, including the white spaces printf("%s", str); }
C语言: 动态分配数组(一维)
数组元素个数为变量
1 2 3 4 5 6 7 8
int *a = NULL; // 声明数组头指针 int N = 0; // 声明变量并初始化 scanf("%d", &N); // 变量赋值 a = (int *) malloc(N * sizeof(int)); // 动态分配内存 /* 之后a的用法与a[N]无异 */ free(a); //!!!i使用结束后必须释放内存空间