eof

fgets() and Ctrl+D, three times to end?

冷暖自知 提交于 2021-01-27 19:22:34
问题 I don't understand why I need press Ctrl + D for three times to send the EOF. In addition, if I press Enter then it only took one Ctrl + D to send the EOF. How Can I make the change so that only took one Ctrl + D then it can detect the EOF? #include <stdio.h> #include <string.h> #include <stdlib.h> #define BUF_SIZE 1024 int main(){ char buffer[BUF_SIZE]; size_t msgLength = 1; char *msg = malloc(sizeof(char) * BUF_SIZE); msg[0] = '\0'; printf("Message: "); while (fgets(buffer, BUF_SIZE, stdin)

What is the End Of File/Stream keyboard combination to use with System.in.read()

廉价感情. 提交于 2021-01-27 06:06:42
问题 Apologize if this trivial question has already been answered, I cannot find it at SO. Reading lines from the IDE console with this Java trivial code (Windows 7 and Eclipse Kepler): int v; try { while ((v = System.in.read()) != -1) System.out.println(v); } catch (IOException e) { ; } How the user can make the value v equal to -1? (I've tried Ctrl + d - z - x - c - s - e and other keys without repeatable behavior, but the loop is interrupted randomly) 回答1: Control + D should send the EOF

What is the End Of File/Stream keyboard combination to use with System.in.read()

﹥>﹥吖頭↗ 提交于 2021-01-27 06:04:59
问题 Apologize if this trivial question has already been answered, I cannot find it at SO. Reading lines from the IDE console with this Java trivial code (Windows 7 and Eclipse Kepler): int v; try { while ((v = System.in.read()) != -1) System.out.println(v); } catch (IOException e) { ; } How the user can make the value v equal to -1? (I've tried Ctrl + d - z - x - c - s - e and other keys without repeatable behavior, but the loop is interrupted randomly) 回答1: Control + D should send the EOF

cin.clear() leave EOF in stream?

柔情痞子 提交于 2020-12-13 05:45:24
问题 I have a question about cin.clear() , my cpp code like this: #include <iostream> using namespace std; int main(void) { char c, d; cout << "Enter a char: " << endl; cin >> c; // here I will enter Ctrl + D (that is EOF under linux) cin.clear(); cout << "Enter another char: " << endl; cin >> d; return 0; } I compiled and run this code under 2 systems: one system is Debian 7 with older version of software like g++ and library g++ --version g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516 Copyright (C)

Bash Script for Load Data Infile MySQL

老子叫甜甜 提交于 2020-12-04 02:25:28
问题 So i'm trying to create a script that I can run that will do a batch import of csv files into a table. I'm having trouble getting the script to work. Here is the script i'm running: #!/bin/bash for f in *.csv do "/opt/lampp/bin/mysql -e use test -e LOAD DATA LOCAL INFILE ("$f") INTO TABLE temp_table FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES (DATE, TIME, SITE_NAME, SITE_IP, TOTAL_TALKTIME, EDGE_UL_BYTES, EDGE_DL_BYTES);" done When I run the