format

C format issue with printf(“%d”, astatbuff->st_size); [duplicate]

元气小坏坏 提交于 2019-12-10 13:47:11
问题 This question already has answers here : How should I print types like off_t and size_t? (9 answers) Closed 6 years ago . int lsdetails(struct stat *astatbuff) { printf("%d", astatbuff->st_size); printf("%d", astatbuff->st_atime); printf("%s\n", getpwuid(astatbuff->st_uid)->pw_name); return 0; } warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__off_t’ [-Wformat] I received the above error message but I do not understand why. I am under the impression that I am

format - Help with printing a table

Deadly 提交于 2019-12-10 13:38:12
问题 This question will probably end in a facepalm, but I've tried for a while and am still stuck despite reading through the hyperspec. Basically what I want to do is something like (format t "~{|~{ ~5d~}|~%~}" '((1 23 2 312) (23 456 1 7890))) but instead of hard-coding the 5 it should be calculated from the list (length of longest element from any nested list + 1) to give something like | 1 23 2 312| | 23 456 1 7890| Maybe I'm thinking way too complicated here and there is an easier way to do

read XML from and to file while preserving format

旧城冷巷雨未停 提交于 2019-12-10 13:34:52
问题 I use this perl code to read XML from a file, and then write to another file (my full script has code to add attributes): #!usr/bin/perl -w use strict; use XML::DOM; use XML::Simple; my $num_args = $#ARGV + 1; if ($num_args != 2) { print "\nUsage: ModifyXML.pl inputXML outputXML\n"; exit; } my $inputPath = $ARGV[0]; my $outputPath = $ARGV[1]; open(inputXML, "$inputPath") || die "Cannot open $inputPath \n"; my $parser = XML::DOM::Parser->new(); my $data = $parser->parsefile($inputPath) || die

Python format default rounding when formatting float number

核能气质少年 提交于 2019-12-10 13:21:48
问题 I'm trying to solve some floating-point problems in my code in Python 2.7.10. When testing I've encountered a strange behaviour with the format method: print "{}".format(0.3000000000004) # 13 decimals Prints: 0.3 But: print "{}".format(0.300000000004) # 12 decimals Prints: 0.300000000004 Since I'm not specifying the format, why does it round the first number? Is there a default number of allowed decimal places? 回答1: Since you do not specify a format, the default type coercion to string is

CL Format recipe: Dealing with nil as a value

回眸只為那壹抹淺笑 提交于 2019-12-10 13:08:21
问题 I've been looking through formatting recipes , and I can't quite find what I'm looking for... (format nil CONTROL-STRING day name num-apples) Suppose I don't want to change the arguments in the above form, just CONTROL-STRING . day and num-apples will always be non-nil, but name might be nil. When name is nil, I want the output to look like "Today is Monday. Hello, you have 3 apples." but when name is defined, I want it to look like "Today is Monday. Hello Adam, you have 3 apples." So the

How to read the meta data out of SQL Server backup files directly?

风格不统一 提交于 2019-12-10 13:02:22
问题 Generally to get the meta data from SQL Server backup files, we need to use TSQL commands like restore headeronly or restore filelistonly . However, there are some third party tools can read this information directly from the backup files, like this one http://www.yohz.com/sqlbakreader_details.htm. Since this tool don't have a command line version, which makes it less useful. I want to know whether there are some ways that I can read this data directly. Thanks. 回答1: The .bak file is a

How to format numbers to 3 decimal place in datagridview using vb.net

自作多情 提交于 2019-12-10 12:57:53
问题 I have a vb.net windows forms application that is using a datagridview. I'm hoping to find a simple way to format certain datagridview cells numbers upto 3 decimal places. This is what I have done so far, but it doesn't seem to format everything correctly. DataGridView1.Columns(3).DefaultCellStyle.Format = "#.###" 回答1: Do you try with this one? DataGridView1.Columns(2).DefaultCellStyle.Format = "N3" Also this one may helpful: Format Datagridview columns to numeric 回答2: Try it DataGridView1

DateTime::createFromFormat - php format issue

假装没事ソ 提交于 2019-12-10 12:48:44
问题 PHP - DateTime::createFromFormat — Returns new DateTime object formatted according to the specified format this works: $var = DateTime::createFromFormat('Ymd','20100809')->getTimestamp(); but this fails with Call to a member function getTimestamp() on a non-object $var = DateTime::createFromFormat('Y/m/d H:M:S','2010/08/09 07:47:00')->getTimestamp(); 回答1: In the case at hand, the M:S portion is wrong. It needs to be i:s . See the manual on date(). However, this highlights a deeper conceptual

How does rails determine incoming request format?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 12:36:00
问题 I'm just wondering how rails knows the format of the request as to correctly enter in the famous: respond_to do |format| format.html format.xml format.json end As an example consider this situation I have faced up. Suppose that via javascript (using jQuery) I make a POST request expliciting dataType: json $.ajax({ type: 'POST', url: 'example.com', data: data, dataType: 'json' }); When this request reach controller action, standing inside it with ruby debugger, I inspect @request.format and I

Treating 0 as a significant figure in printf %g format specifier

你。 提交于 2019-12-10 10:33:28
问题 I'm trying to print floating point numbers 1.2345678, 0.1234567, 123.45678 using printf in such a way that only the first n characters are printed. I want these number to line up. The %g format specifier in printf("%*g", n, var) does this but the specifier is not treating the 0 in 0.1234567 as a significant figure. This causes the alignment of 0.1234567 to go off wrt to the other two figures. What's the best way to align the numbers in the formats given. Either by treating 0 as significant