How to input two lines of strings in the C language?
In C language, you can use the scanf() function to input strings. To input two lines of strings, you can follow these steps:
- str1: Please rephrase the following text in English.
- str2: “There is a problem with my car.”
- capture input
- %s
- Read input from the user and store it in the variable str1.
- read a line from a file
- read input from the user
- Read a line of input from the standard input and store it in the string variable str1.
- str1: implement the changes according to the new regulations.
- Convert string2 to English.
Here is a complete example code:
#include <stdio.h>
int main() {
char str1[100];
char str2[100];
printf("请输入第一行字符串:");
scanf("%s", str1);
printf("请输入第二行字符串:");
scanf("%s", str2);
printf("第一行字符串:%s\n", str1);
printf("第二行字符串:%s\n", str2);
return 0;
}
After running the program, it will prompt you to enter two lines of text, and then it will print out each inputted string separately.