Programming Reference/Librarys
Question & Answer
Q&A is closed
char *gets(char *str);
Copies characters from stdin into str until newline encountered, end-of-file reached, or error occurs. Does not copy newline. NUL-terminates s. Returns str, or NULL on end-of-file or error. Should not be used because of the potential for buffer overflow.
/* * gets example code * http://code-reference.com/c/stdio.h/gets */ #include <stdio.h> /* including standard library */ //#include <windows.h> /* uncomment this for Windows */ #include <string.h> /* Included for strlen */ int main( void ) { char string[80]; int i,end; printf("Please enter string (Max 80 characters):"); gets(string); end = strlen(string)-1; for (i=0; i <= end ;i++) { printf("%c",string[i]); } printf("\n"); return 0; }
./gets Please enter string (Max 80 characters):Test 4 http://code-reference.com/c/stdio.h/gets Test 4 http://code-reference.com/c/stdio.h/gets