? Linux ???,gets()
????????????,????????????
- ??
fgets()
????gets()
???fgets()
????????????????,??????????????
#includeint main() { char buffer[256]; printf("Enter a string: "); fgets(buffer, sizeof(buffer), stdin); printf("You entered: %s", buffer); return 0; }
- ??
getline()
???getline()
?????????????????????,????,????????????????
#include#include int main() { char *buffer = NULL; size_t len = 0; ssize_t read; printf("Enter a string: "); read = getline(&buffer, &len, stdin); if (read != -1) { printf("You entered: %s", buffer); } free(buffer); return 0; }
- ??
scanf()
???,????%s
??????????????
#includeint main() { char buffer[256]; printf("Enter a string: "); scanf("%5s", buffer); // ??:?????255???256,??C??????????????????'\0' printf("You entered: %s", buffer); return 0; }
??,???? gets()
??,????????????,????????????????