我想通过将今天的日期作为一周中除星期日以外的所有日子的输入来打印上周日的日期,但如果是星期日,则它应该打印今天的日期。我试过这个,
a=`date -dlast-sunday +%Y%m%d`
Run Code Online (Sandbox Code Playgroud)
但这在最后一个日期之前给出了星期日的日期。
我有UITableView1个部分和numberOfRows:来自NSMutableArray.
我想要的是每当UITableView出现滚动视图时必须滚动到最后一行.
为此我想要indexPath最后一行.怎么弄?
我知道这个问题已被多次回答.但这些方法都不适合我.
这是我试过的代码
-(NSIndexPath*)lastIndexPath{
NSInteger sectionsAmount = [myTableView numberOfSections];
NSInteger rowsAmount = [myTableView numberOfRowsInSection:sectionsAmount-1];
NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:(rowsAmount - 1) inSection:(sectionsAmount - 1)];
return lastIndexPath;
}
Run Code Online (Sandbox Code Playgroud) 我在一段相当简单的代码上遇到了一个奇怪的问题.代码的相关部分如下:
void foo(int32 in_sd_id, int32 out_sd_id)
{
int32 nsds; /* number of data sets in the file */
int32 nattr; /* number of global attributes in the file */
int32 attr_cnt; /* count of number of attribute */
int32 attr_index; /* attribute index */
int32 attr_type, attr_size; /* attribute type and size */
char attr_name[40];
ret = SDfileinfo(in_sd_id, &nsds, &nattr);
printf("nattr is %d\n", nattr);
/* test to see if num_datasets and num_global_attr can be retrieved from in_sd_id */
if (ret …Run Code Online (Sandbox Code Playgroud) 为什么这段代码不起作用?
#include<stdio.h>
#include<stdlib.h>
int main(int argc,char **argv){
char * new;
new = malloc(10);
const char * s1 = "hello";
while(*s1){
*new++ = *s1++;
}
printf("%s",new);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我运行了gdb,发现*s1没有分配给*new.为什么?
在c代码中.我有一个输入文件(称为in),格式为mad-lib,"我真的有<形容词>眼睛"(<>中没有空格)我想写一个bool函数,使用scanf来读取每个单词并返回true如果单词以'<'开头(也称为标记)我该怎么做呢?是的,我必须使用scanf.这是我现在所拥有的,但我不认为这是完全正确的,所以另一个问题是,我怎么知道我的功能是否正常工作.
/* istoken = returns true if word is a token */
bool istoken(char word[]) {
char first;
int firstindex;
while (1) {
scanf("%s", word);
first = word[MAX_LEN];
firstindex = (int)strlen(word);
if (first == '<') {
printf("The token is: %s\n", first);
return true; }
else {
return false; }
}
}
Run Code Online (Sandbox Code Playgroud) 我正在获取核心转储,我一直在寻找,似乎我做的一切都正确。
int len = 0;
char *buff = NULL;
size_t sz;
if(getline(&buff,&sz, stdin) > 0){
while(isalpha(*buff++))
++len;
printf(" 1st word %d characters long ",len);
}
free(buff);
Run Code Online (Sandbox Code Playgroud) 我有一个带有列的大 csv 文件
id,name,sex,ethnicity,hometown,organization,id_card_num,address,mobile_num,phone_num,education
Run Code Online (Sandbox Code Playgroud)
问题是用双引号括起来的组织列,并且在某些行上用 \n 换行符分成两行。我只需要加入符合此条件的行。
这个程序打印6.
如果我取消注释该//printf("yes");行,则打印8但不打印yes.
如果我删除第一个i++;并将该行留空,则会打印出来7.
如果我删除i++;它打印的第二个5.似乎无法找到它.
int main ( ) {
int i = 3;
if (!i)
i++;
i++;
if (i==3)
//printf("yes");
i+=2;
i+=2;
printf("%d", i);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 尝试打印多于15个小数位的PI结果会导致在第15个小数位之后打印不正确的小数。尽管分配了30个正确的十进制值,并且使用long double来保留该值。以下测试案例清楚地显示了该错误。
这是出乎意料的。如果数字中有任何错误,我希望在用尽IEEE-754位数之后直到第25位都不会看到任何错误。这里发生的是什么规则可能可以解释,我无法打印回我刚刚分配给以下sPI的相同30位数字。这也会影响打印中M_PI包含的表示形式的能力math.h。
#include <stdio.h>
int
main (void) {
// static PI approximation (glibc man 1.17)
long double sPI = 3.14159265358979323846264338327;
char strPI[] = "3.14159265358979323846264338327";
printf ("\n %s (strPI - string - correct)\n", strPI);
printf (" %.29Lf (sPI - long double - INCORRECT)\n\n", sPI);
return (0);
}
Run Code Online (Sandbox Code Playgroud)
输出:
3.14159265358979323846264338327 (strPI - string - correct)
3.14159265358979311599796346854 (sPI - long double - INCORRECT)
^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
大概,此十进制错误将适用于精度大于16的任何十进制数字。当以字符串形式打印时,PI可以正常打印(显然),但是以双精度形式打印时-小数精度会在第15个小数点后下降。是什么原因造成的?
非常有趣,正如建议L在浮点文字的末尾添加一个确实有帮助:
3.14159265358979323846264338327 (strPI - string - correct) …Run Code Online (Sandbox Code Playgroud)