delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/12/06/14:41:14

From: fwibbly AT earthlink DOT net (Paul Wilson)
Subject: B20: fgets() again. (Enter isn't enter!)
6 Dec 1998 14:41:14 -0800 :
Message-ID: <366AC82B.C9DF9A0C.cygnus.gnu-win32@earthlink.net>
Mime-Version: 1.0
To: gnu-win32 AT cygnus DOT com

I found that using ^J instead of enter gives the correct results.

Take this small bit of code:

#include <stdio.h>

char string[5];
char *fgets_ptr;

int main() {
	fgets_ptr = fgets(string, sizeof(string), stdin);
	string[strlen(string)-1] = '\0';
	printf("fgets_ptr is %s and string is %s\n", fgets_ptr, string);
	return(0);
}

Yeilds this when using "Enter" to execute it:

BASH.EXE-2.02$ ./fgetstest.exe

fgets_ptr is  and string is

But yeilds this when using ^J:

BASH.EXE-2.02$ ./fgetstest.exe^J
asd
fgets_ptr is asd and string is asd

Paul
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019