stdin

C - Better method for replacing

自古美人都是妖i 提交于 2019-12-11 07:58:56
问题 I'm looking to replace words from a file where words.txt contains "banana test apple" would output -> "banana Replaced! apple" The words it would be looking to replace would come as an argument to stdin ("test" in this case) Not sure where my code is going wrong, and I'm also wondering if there's a better way to do it than get getchar() function, as I find it confusing to work with, and annoying as you cannot backup characters. Any suggestions? Thanks $ ./a.exe test < words.txt #include

Using C Readline to read a line from file instead of stdin

谁说我不能喝 提交于 2019-12-11 07:08:52
问题 I'm using the readline from gcc -lreadline for reading from stdin. Later, I want to read from a file, so I tried the following, but it still paused for and accepted input from command prompt instead of accepting it from the file. Is there a fix for this approach? FILE* savedStdin = stdin; stdin = fopen("someFile.txt", "r"); char* input = readline(NULL); stdin = savedStdin; 回答1: The readline library is actually pretty flexible and can almost certainly be tortured to do what you want. But it

Reading an unknown number of lines with unknown length from stdin

心不动则不痛 提交于 2019-12-11 06:06:27
问题 I'm relatively new to programming in C and am trying to read input from stdin using fgets . To begin with I thought about reading max 50 lines, max 50 characters each, and had something like: int max_length = 50; char lines[max_length][max_length]; char current_line[max_length]; int idx = 0; while(fgets(current_line, max_length, stdin) != NULL) { strcopy(lines[idx], current_line); idx++; } The snippet above successfully reads the input and stores it into the lines array where I can sort and

iisnode: Unknown stdin file type

☆樱花仙子☆ 提交于 2019-12-11 06:03:44
问题 I have iisnode working smoothly on win8/IIS8. I created a very simple hello world and it works great. However, when I try to use process.stdin I get the following error: Application has thrown an uncaught exception and is terminated: Error: Implement me. Unknown stdin file type! at process.startup.processStdio.process.openStdin [as stdin] (node.js:405:17) at Object.<anonymous> (C:\ApprendaPlatform\SiteData\developer\v1\root\shim\node_modules\actionhero\bin\zzz.js:7:20) at Module._compile

Read input from StdIn when redirecting StdIn to python manage.py shell

我的未来我决定 提交于 2019-12-11 05:36:15
问题 I have a python script that I call redirecting it to Django manage.py shell . $ python manage.py shell < script.py I want to take an answer from user to decide what to do. But I can't do it neither with input() or sys.stdin.readline() . With input() answer = input('A question') if answer == 'y': # Do something else: pass Error: EOFError: EOF when reading a line With sys.stdin.readline: answer = sys.stdin.readline() if answer == 'y': # Do something else: pass In this case script continues

echoing of getchar and '\n' char from stdin

纵饮孤独 提交于 2019-12-11 05:09:29
问题 I have already looked at this similar question but i am still wondering if there is another way to stop 1) the terminal echoing with portabilty as this is an assignment and I have already had one java program crash and burn on my teachers computer 2) in my program i search for a '\n' char then if it isn't the first char use getchar then putchar till the next '\n' char which works fine when using redirected stdin but when I try using the program without redirection the enter key is always

Trouble with Python JSON input from STDIN

混江龙づ霸主 提交于 2019-12-11 04:47:51
问题 input = json.load(sys.stdin) print(input['id']) When I input {"id":1} and hit enter, my program does not continue, I am just stuck typing in my input. How can I make the program continue after valid json has been passed to my stdlin? 回答1: when you read in from sys.stdin it will read everything until it hits an EOF character normally ctrl-d so if you input {"id":1} <ENTER> ctrl-d it should work. It looks like what you are trying to do is something like this import json json_as_str = input()

Two processes reading the same stdin

佐手、 提交于 2019-12-11 04:47:26
问题 In a C program, I have a menu, with some options to choose from, represented by characters. There's an option that forks the process, and runs a function (we can say it runs in the background). This function that runs in the background, under some conditions, can ask the user to enter data. My problem is: when the main process is asking for data (or option) and the child process is asking for data too, I can't send the data properly. Do you have any idea on how to deal with this? I'll add a

How to print commands in Python?

﹥>﹥吖頭↗ 提交于 2019-12-11 04:09:25
问题 I'm not in the programming area but I recently got interested in Python. I was writing some functions but for debugging I need to see what commands are running. For instance: def foo(): for i in xrange(0,5): a = 1 + i Is it possible to make the interpreter output >>> for i in xrange(0,5) >>> a = 1 + 0 >>> a = 1 + 1 >>> a = 1 + 2 >>> a = 1 + 3 >>> a = 1 + 4 For >>> foo() Or at least write to a file what is happening? I did some scripting in the past and I remember that this was possible in DOS

Redirect Stdin and Stdout to File

倖福魔咒の 提交于 2019-12-11 03:24:02
问题 I'm currently the Teaching Assistant for an Introduction to C class. The class is being taught using Visual Studio, but when grading I just use a simple Windows batch script to process all the assignment submissions, compile them, run them on a test file, and redirect the output to a series of text files I can print out, mark up, and hand back to students. The whole process works very well, except for the fact that when I redirect stdin, it does not appear in the redirected stdout the same