ansi

Adding colors to terminal prompt results in large white space

a 夏天 提交于 2019-12-03 16:57:11
I'm working on a simple cli script and wanted to add some color to the following code: rl.question('Enter destination path: ', function(answer) { // ... }); rl.write('/home/' + user + '/bin'); Which displays in the terminal: Enter destination path: /home/jmcateer/bin_ But I wanted to add some color to the prompt I did the following: rl.question('\u001b[1;36mEnter destination path:\u001b[0m ', function(answer) { }); rl.write('/home/' + user + '/bin'); And the command line prompt ended up displaying: Enter destination path: /home/jmcateer/bin_ It works but there's a huge amount of white space I

Where to get the latest ANSI C standard document [closed]

假装没事ソ 提交于 2019-12-03 10:56:53
Where can I find the latest ANSI C standard document? You can buy it here (ISO/IEC 9899:2011): http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=57853 Price is around USD 240. You can also get the latest (April 12, 2011) draft version for free: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf UPDATE (June 16, 2016): C11 has also been ratified by ANSI. The ANSI store is selling C11 document (essentially the same document as the ISO one) for a cheaper price: USD 60 (as of June 16, 2016). ISO store also lowered their price for C11, from CHF 238 to CHF 198

Print new line to a text file without carriage return (CR) in windows

。_饼干妹妹 提交于 2019-12-03 08:36:34
I am writing a program in C that prints a random hexadecimal value to a text file. The printed value has a carriage return (CR) along with a line feed (LF). However, the CR (visible in notepad++) is causing issues when the file is used. Is there a way to print a new line with just the LF and no CR. This is the code: #include <stdio.h> #include <stdlib.h> void main(){ int hexa_address, numberofAddress; char tracefile[50]; //name of file int seq_or_rand; //1 for random address; 2 for sequential address srand(time(NULL)); //reset the value of the random printf("This generator generates 32bits

GCC options for strictest C code? [duplicate]

我只是一个虾纸丫 提交于 2019-12-03 08:35:26
问题 This question already has answers here : Recommended gcc warning options for C [closed] (15 answers) Closed 5 years ago . What GCC options should be set to have GCC as strict as possible? (and I do mean as strict as possible) I'm writing in C89 and want my code to be ANSI/ISO compliant. 回答1: I'd recommend using: -Wall -Wextra -std=c89 -pedantic -Wmissing-prototypes -Wstrict-prototypes \ -Wold-style-definition You should compile with -O as well as -g as some warnings are only available when

Windows API ANSI functions and UTF-8

 ̄綄美尐妖づ 提交于 2019-12-03 05:42:47
Is it possible to use Windows API ANSI functions with UTF-8 strings? For example, say I have a path encoded in UTF-8. Can I call CreateDirectoryA or CreateFileA and use a UTF-8 path, or do I have to perform some conversion before calling the functions? No. Use MultiByteToWideChar to convert UTF-8 to UTF-16 and then call the wide character APIs such as CreateDirectoryW or CreateFileW . An easier approach (than using raw Win32 API MultiByteToWideChar) would be to use ATL conversion helpers , like CA2CW . You can specify CP_UTF8 as code page (second parameter in the constructor), to convert from

How to find text between two strings in c

别说谁变了你拦得住时间么 提交于 2019-12-03 04:06:28
I need to extract the text between 2 string patterns in c. Example: aaaaaa<BBBB>TEXT TO EXTRACT</BBBB>aaaaaaaaa PATTERN1=<BBBB> PATTERN2=</BBBB> Thanks. Here is an alive example of how to do this #include <stdio.h> #include <string.h> int main(void) { const char *s = "aaaaaa<BBBB>TEXT TO EXTRACT</BBBB>aaaaaaaaa"; const char *PATTERN1 = "<BBBB>"; const char *PATTERN2 = "</BBBB>"; char *target = NULL; char *start, *end; if ( start = strstr( s, PATTERN1 ) ) { start += strlen( PATTERN1 ); if ( end = strstr( start, PATTERN2 ) ) { target = ( char * )malloc( end - start + 1 ); memcpy( target, start,

how to read a file that can be saved as either ansi or unicode in python?

与世无争的帅哥 提交于 2019-12-03 04:03:38
I have to write a script that support reading of a file which can be saved as either Unicode or Ansi (using MS's notepad). I don't have any indication of the encoding format in the file, how can I support both encoding formats? (kind of a generic way of reading files with out knowing the format in advanced). MS Notepad gives the user a choice of 4 encodings, expressed in clumsy confusing terminology: "Unicode" is UTF-16, written little-endian. "Unicode big endian" is UTF-16, written big-endian. In both UTF-16 cases, this means that the appropriate BOM will be written. Use utf-16 to decode such

Getting Control Flow Graph from ANSI C code

不羁岁月 提交于 2019-12-03 02:27:35
问题 I'm building tool for testing ansi c applications. Simply load code, view control flow graph, run test, mark all vertexes which was hit. I'm trying to build CFG all by myself from parsing code. Unfortunately It gets messed up if code is nested. GCC gives ability to get CFG from compiled code. I might write parser for its output, but I need line numbers for setting breakpoints. Is there way for getting line numbers when outputting Control Flow Graph with -fdump-tree-cfg or -fdump-tree-vcg ?

Converting UTF8 to ANSI with Ruby

痞子三分冷 提交于 2019-12-03 02:06:16
I have a Ruby script that generates a UTF8 CSV file remotely in a Linux machine and then transfers the file to a Windows machine thru SFTP. I then need to open this file with Excel, but Excel doesn't get UTF8, so I always need to open the file in a text editor that has the capability to convert UTF8 to ANSI. I would love to do this programmatically using Ruby and avoid the manual conversion step. What's the easiest way to do it? PS: I tried using iconv but had no success. ascii_str = yourUTF8text.unpack("U*").map{|c|c.chr}.join assuming that your text really does fit in the ascii character set

GCC options for strictest C code? [duplicate]

ε祈祈猫儿з 提交于 2019-12-02 22:22:22
This question already has an answer here: Recommended gcc warning options for C [closed] 15 answers What GCC options should be set to have GCC as strict as possible? (and I do mean as strict as possible) I'm writing in C89 and want my code to be ANSI/ISO compliant. Jonathan Leffler I'd recommend using: -Wall -Wextra -std=c89 -pedantic -Wmissing-prototypes -Wstrict-prototypes \ -Wold-style-definition You should compile with -O as well as -g as some warnings are only available when the optimizer is used (actually, I usually use -O3 for spotting the problems). You might prefer -std=gnu89 as that