stdio

Writing to stdin from PHP?

眉间皱痕 提交于 2019-12-30 09:00:23
问题 In linux I want to run a gnome zenity progress bar window from PHP. How zenity works is like this: linux-shell$ zenity --display 0:1 --progress --text='Backing up' --percentage=0 10 50 100 So the first command opens the zenity progress bar at 0 percent. Zenity then takes standard input numbers as the progress bar percentage (so it will go from 10% to 50% to 100% when you type those numbers in). I can't figure out how to get PHP to type in those numbers though, I have tried: exec($cmd); echo

Writing to stdin from PHP?

自作多情 提交于 2019-12-30 09:00:08
问题 In linux I want to run a gnome zenity progress bar window from PHP. How zenity works is like this: linux-shell$ zenity --display 0:1 --progress --text='Backing up' --percentage=0 10 50 100 So the first command opens the zenity progress bar at 0 percent. Zenity then takes standard input numbers as the progress bar percentage (so it will go from 10% to 50% to 100% when you type those numbers in). I can't figure out how to get PHP to type in those numbers though, I have tried: exec($cmd); echo

Clang Error - stddef file not found?

痴心易碎 提交于 2019-12-30 04:12:53
问题 After upgrading to Ubuntu 13.10 "Saucy", Clang now gives me the error message: clang -Wall -Werror -std=c99 -ggdb -O0 5.1.c -o 5.1 In file included from 5.1.c:1: /usr/include/stdio.h:33:11: fatal error: 'stddef.h' file not found # include <stddef.h> ^ 1 error generated. make: *** [5.1] Error 1 BTW the header I included was stdio.h not stddef.h but I am assuming that stdio.h references or #includes stddef.h 回答1: This error appeared for me when trying to run clang-tidy without clang installed.

C equivalent of autoflush (flush stdout after each write)?

只谈情不闲聊 提交于 2019-12-28 16:31:27
问题 In Perl, I can type: $|++; and anything printed to STDOUT will be automatically fflush()ed. Is there an equivalent in C? In other words, is there some way I can tell stdio to automatically fflush stdout after every printf(), the way it automatically flushes stderr? 回答1: Try setvbuf(stdout, NULL, _IONBF, 0) . It changes stdout to unbuffered ( _IONBF ) mode. 回答2: I haven't done this, but _IOLBF would be the right answer. $ man setvbuf NAME setvbuf — assign buffering to a stream SYNOPSIS

Tried and true simple file copying code in C?

我怕爱的太早我们不能终老 提交于 2019-12-28 04:03:45
问题 This looks like a simple question, but I didn't find anything similar here. Since there is no file copy function in C, we have to implement file copying ourselves, but I don't like reinventing the wheel even for trivial stuff like that, so I'd like to ask the cloud: What code would you recommend for file copying using fopen()/fread()/fwrite()? What code would you recommend for file copying using open()/read()/write()? This code should be portable (windows/mac/linux/bsd/qnx/younameit), stable,

fastest way to write integer to file in C

大憨熊 提交于 2019-12-27 04:00:06
问题 I am doing a homework to programming in C. Bonus points are for quick writing to the file in there upload test system. I am trying to write a number of lines each comprising three space delimited decimal integer strings and then '\n' in file. The problem is, that fprintf is too slow (their reference time is more or less 1/3 faster). I have tried a lots of possibilities (everything is in one for loop). fprintf (too slow): fprintf(f, "%d %d %d\n", a[i], b[i], c[i]); converting to string and

fprintf function not working but it returns positive number

浪尽此生 提交于 2019-12-25 05:07:26
问题 I'm using fprintf in the following way. Everything seems to be ok but fprintf doesn't print to my file at all! fprintf(pFile, "%s\n", "print"); Something that is strange is that fprintf returns OK . it returns 6 in the above code, but not printing to file! The file is created successfully but is empty. changing it to printf is printing and OK too. 回答1: fprintf and the other stdio output functions are buffered, which means that the output is first stored in memory, and not actually printed

how to get multiple character in one input in C

落爺英雄遲暮 提交于 2019-12-25 02:19:54
问题 I'm new to C programming so i'm trying to write a piece of code where i need to take ip address in hexadecimal but i couldn't figure out how to do. as far as i know i can't get multiple input with char but with int when user enters 'A' for example it turns out huge number. for decimal inputs i wrote something like this int main(){ int IP_1,IP_2,IP_3,IP_4; printf("Enter the IP address:\n"); scanf("%d.%d.%d.%d",&IP_1,&IP_2,&IP_3,&IP_4); i used 4 variables because later i will use those numbers

Glob in C++ and print the results

こ雲淡風輕ζ 提交于 2019-12-24 12:00:25
问题 I'm just trying to glob everything in a directory and print the list of results, but I get an empty printf: #include <glob.h> #include <stdio.h> int main() { int result; glob_t buffer; buffer.gl_offs = 10; glob("*", GLOB_DOOFFS, NULL, &buffer); printf((char*)buffer.gl_pathv); } What does work is printf("%i", buffer.gl_pathc)); 回答1: Do you need to reserve empty slots in glob? Do not include GLOB_DOOFFS if you don't need it. And don't forget to free memory for glob. Try something like this:

Simple encryption/decryption algorithm causing EOF

孤者浪人 提交于 2019-12-24 10:38:56
问题 I was playing with very simple encryption/decryption algorithm like this; #include <stdio.h> #include <stdlib.h> #define BUFFESIZE 1024 int main(int argc, char *argv[]) { int keylen = 0; char *key = argv[1]; char *buffer = NULL; size_t buffersize = 0; size_t nbytes = 0; size_t nread; int i = 0; while(*key++ != 0) keylen++; key = argv[1]; do { buffersize+=BUFFESIZE; buffer = realloc(buffer, buffersize); nread = fread(buffer+nbytes, 1, BUFFESIZE, stdin); nbytes+=nread; } while (nread > 0); for