How to output a string in the C language?
In C language, there are several methods to output strings.
- The printf function is the most commonly used output function in the C language, and can be used to print strings. For example:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
- The puts function is used to output strings and automatically adds a new line at the end. For example:
#include <stdio.h>
int main() {
puts("Hello, World!");
return 0;
}
- The fputs function is used to output a string to a specified file stream. For example:
#include <stdio.h>
int main() {
FILE *file = fopen("output.txt", "w");
if (file != NULL) {
fputs("Hello, World!", file);
fclose(file);
}
return 0;
}
All of these methods can be used to output strings, and the specific method to use depends on your needs.