User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdio.h:gets

Table of Contents

gets

    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.

C Sourcecode Example

/* 
 * 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;
}

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
c/stdio.h/gets.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz