#include <stdio.h>
int myfunc(char *str)
{
char *ptr =str;
while(*ptr++);
printf("%s %s\n",str,ptr);
return ptr-str-1;
}
int main()
{
printf("%d\n", myfunc("Princess Leia"));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
Princess Leia %d
13
Run Code Online (Sandbox Code Playgroud)
ptr如何%d成为字符串?又为何ptr-str-1是13?
我有shell脚本,它根据文本文件中的值生成sql查询.我的文本文件的值如下(逐行)

我的shell脚本就是这个.
#!/bin/sh
NAME="tableNames.txt"
COLUMNA="ca"
COLUMNB="cb"
cat $NAME | while read LINE
do
echo "CREATE TABLE \"$LINE\" (
forward_speed double precision,
backward_speed double precision
);"
done
Run Code Online (Sandbox Code Playgroud)
LINE变量正确地从文本文件中获取值,但它有换行符如何删除换行符.
我想知道这两个命令有什么区别..
find . –name *.txt
find . –name "*.txt"
Run Code Online (Sandbox Code Playgroud)
我在系统中运行它并且找不到任何区别,标志有" "什么作用?
我有一个code.ps文件转换为code.pdf,我想将其添加到test.pdf中每个页面的末尾,即缩小test.pdf的每个页面并在其末尾添加一个图像.
我已经编写了以下shell脚本,但它在test.pdf的每一页之后将code.pdf附加为新页面!...请帮助.这是我的代码: -
#!/bin/sh
filename=test.pdf
pages="`pdftk $filename dump_data | grep NumberOfPages | cut -d : -f2`"
numpages=`for ((a=1; a <= $pages; a++)); do echo -n "A$a B1 "; done`
pdftk A=$filename B=code.pdf cat $numpages output $filename-alternated.pdf
exit 0
Run Code Online (Sandbox Code Playgroud) 我正在寻找创建RegEx模式
[a-zA_Z]我创建了这个模式:
^(?=.*[0-9].*[0-9])[0-9a-zA-Z]{8}$
Run Code Online (Sandbox Code Playgroud)
这种模式工作正常,但我只想要一个数字.例:
aaaaaaa6 match
aaa7aaaa match
aaa88aaa don't match
aaa884aa don't match
aaawwaaa don't match
Run Code Online (Sandbox Code Playgroud) 我试图在虚拟机上的Ubuntu上安装libxml2-2.9.1.我按照以下链接中的步骤进行操作:http : //www.linuxfromscratch.org/blfs/view/svn/general/libxml2.html http://www.geeksww.com/tutorials/libraries/libxml/installation/ installing_libxml_on_ubuntu_linux.php#评论
我在编译步骤后陷入困境.当我按照任何一个链接时,我会遇到同样的错误.错误是
make[3]: Leaving directory `/home/abhijit/Documents/libxml2-2.9.1/doc/examples'
make[2]: Leaving directory `/home/abhijit/Documents/libxml2-2.9.1/doc'
Making all in example
make[2]: Entering directory `/home/abhijit/Documents/libxml2-2.9.1/example'
CC gjobread.o
CCLD gjobread
make[2]: Leaving directory `/home/abhijit/Documents/libxml2-2.9.1/example'
Making all in xstc
make[2]: Entering directory `/home/abhijit/Documents/libxml2-2.9.1/xstc'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/abhijit/Documents/libxml2-2.9.1/xstc'
Making all in python
make[2]: Entering directory `/home/abhijit/Documents/libxml2-2.9.1/python'
make all-recursive
make[3]: Entering directory `/home/abhijit/Documents/libxml2-2.9.1/python'
Making all in .
make[4]: Entering directory `/home/abhijit/Documents/libxml2-2.9.1/python'
CC libxml.lo
libxml.c:14: fatal error: Python.h: No such …Run Code Online (Sandbox Code Playgroud) 有没有人知道使用GTK的文件处理.我需要以"w +"模式打开文件并写入.我不知道GTK中是否存在文件处理.下面是我需要的GTK格式的'C'程序示例.
#include <stdio.h>
int main(int argc, char *argv[]) {
int a = 5;
float b = 3.14;
FILE *fp;
fp = fopen( "test.txt", "w+" );
fprintf( fp, " %d %f", a, b );
fwrite(----);
fclose( fp );
}
Run Code Online (Sandbox Code Playgroud) s='id;some text here with possible ; inside'
IFS=';' read -r id string <<< "$s"
echo "$id"
Run Code Online (Sandbox Code Playgroud)
restore.sh: 2: restore.sh: Syntax error: redirection unexpected
Run Code Online (Sandbox Code Playgroud)
bash版本 GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)
我目前正在开发一个项目,要求我有一个从0.9到1.2的列表,步长为0.01.我尝试了以下方法:
init = float(0.9)
l = []
for i in range(0,31):
l[i]= init + ( float(i) / 100 )
Run Code Online (Sandbox Code Playgroud)
但是,python给了我以下输出:
回溯(最近一次调用最后一次):IndexError中的文件"",第2行:列表赋值索引超出范围
任何人都可以帮我解决这个问题吗?
我最近在考试中被问到为什么我们(String args[ ])只在java中使用main ?为什么我们不在(String args[ ])任何其他编程语言中使用main ?