小编myd*_*dsl的帖子

计算句子中的字符,单词,单词长度和总长度

我必须编写一个脚本,它接受一个句子并打印字数,字符数(不包括空格),每个单词的长度和长度.我知道wc -m在单词中有反字符数,但如何在脚本中使用它?

#!/bin/bash

mystring="one two three test five"
maxlen=0;
for token in $mystring; do
  echo -n "$token: ";
  echo -n $token | wc -m;
    if [ ${#token} -gt $maxlen ]; then 
      maxlen=${#token}; fi;
done

echo "--------------------------";
echo -n "Total words: ";
echo "$mystring" | wc -w;
echo -n "Total chars: ";
echo "$mystring" | wc -m;
echo -n "Max length: "; 
echo $maxlen
Run Code Online (Sandbox Code Playgroud)

shell wc

10
推荐指数
2
解决办法
8万
查看次数

c使用lseek以相反的顺序复制文件

我已经有了如何从一开始就将一个文件复制到另一个文件,但是我如何修改程序以相反的顺序复制它?源文件应具有读访问权和目标文件读写执行权.我必须使用文件控制库.

例如

FILE A            File B should be
|---------|        |----------|
|ABCDEF   |        |FEDCBA    |
|---------|        |----------|
Run Code Online (Sandbox Code Playgroud)

*********************更新**********

感谢MikeNakis的提示和建议,Sangeeth为您的代码

我已经重做了代码,现在它是以反向顺序打印文件大小的复制字节

这是代码

#include<stdlib.h>
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
#include<sys/stat.h>
#include<unistd.h>

int main(int argc, char *argv[]) {

    int source, dest, n;
    char buf;
    int filesize;
    int i;

    if (argc != 3) {
        fprintf(stderr, "usage %s <source> <dest>", argv[0]);
        exit(-1);
    }

    if ((source = open(argv[1], …
Run Code Online (Sandbox Code Playgroud)

c posix file filestream

5
推荐指数
1
解决办法
1万
查看次数

c共享内存附加/分离/解除分配

我对使用POSIX系统调用的c中的共享内存分段有疑问.我是从客户端和服务器分离和删除段是否正确,或者我只需要从服务器中删除?

考虑我有2个程序

一个用于服务器,一个用于客户端

the steps for the server

1)create memory segment
2)attach
3)detach
4)remove

steps for the client

1)create
2)attach
3)detach
4)remove
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

//server

#include<stdlib.h>
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<sys/shm.h>

#define SHMSZ 100
int main()
{

key_t key;
char c;
int shmid;
char *shm;

key=1025;

//locate
if((shmid=shmget(key,SHMSZ,0666 | IPC_CREAT))<0)
{
perror("shmget");
exit(-1);
}



//attach
if((shm=shmat(shmid,NULL,0))==(char*)-1)
{
perror("shmat");
exit(-1);
}


sprintf(shm,"Hi there");

//shm="Hi There";

while(*shm!='*');
sleep(1);

//detach
shmctl(shmid,IPC_RMID,NULL);
return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是客户端

//client

#include<stdlib.h>
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<sys/shm.h>

#define SHMSZ …
Run Code Online (Sandbox Code Playgroud)

c client posix shared-memory

4
推荐指数
1
解决办法
4017
查看次数

Java Oracle jdbc SELECT语句

我在Eclipse环境中使用java练习Oracle JDBC.我理解如何SELECT * from product通过迭代使用表的每一行来输出next().我正在努力输出声明

SELECT pid, pname 
from product 
where price>20
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

import java.sql.*;


public class intro {

    /**
     * @param args
     */
    public static void main(String[] args)
    {
    //  throws SQLException

        //initiazlie the connection

        Connection con=null;

        try //try connection to database
        {
            //load driver
            Class.forName("oracle.jdbc.OracleDriver");
            System.out.println("Oracle JDBC driver loaded ok.");
            con=DriverManager.getConnection("jdbc:oracle:thin:test/123321@localhost:1521:orcl");
            System.out.println("Connect with @oracle:1521:orcl");

            //declaring statement
            Statement stmt = con.createStatement();

            String dropProductTable="drop table product cascade constraints";

            //create string
            String createProductTable="CREATE TABLE product(" +
             "pid …
Run Code Online (Sandbox Code Playgroud)

java sql oracle jdbc

4
推荐指数
2
解决办法
3万
查看次数

使用Mathematica求解递归关系

晚上好,专家

我想用mathematica求解递推方程,

x(n) = x(n ? 1) + n 
for n > 0, 
    x(0) = 0
Run Code Online (Sandbox Code Playgroud)

我需要找到x(1),x(2),x,(3)

这是我的输入,它给了我错误

n > 0
a[0] := 0
RSolve[x == a[n - 1] + n, a[n], n]
Run Code Online (Sandbox Code Playgroud)

如何使用mathematica重写等式?提前致谢

recurrence wolfram-mathematica

2
推荐指数
1
解决办法
1965
查看次数

标签 统计

c ×2

posix ×2

client ×1

file ×1

filestream ×1

java ×1

jdbc ×1

oracle ×1

recurrence ×1

shared-memory ×1

shell ×1

sql ×1

wc ×1

wolfram-mathematica ×1