User Tools

Site Tools


c:stdio.h:gets

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:stdio.h:gets [2013/01/22 22:02]
c:stdio.h:gets [2024/02/16 01:05] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +===== gets =====
 +
 +<code c>
 +    char *gets(char *str); 
 +</code>
 +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.
 +
 +===== C Sourcecode Example =====
 +<code c>
 +/* 
 + * 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;
 +}
 +
 +</code>
 +
 +==== output ====
 +     ./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
  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War

Impressum Datenschutz