小编Man*_*son的帖子

说话失败不绑定到TTS引擎

所以我有一个原始活动与基本相同的说话代码,但我不得不将该代码移动到另一个活动.我能说的唯一区别是文本到语音不是在异步方法中调用的.说话发生在speakFull方法中.我收到这些错误:

speak failed: not bound to TTS engine
isSpeaking failed: not bound to TTS engine
Run Code Online (Sandbox Code Playgroud)

我是Android开发的新手,我已经通过其他解决方案搜索了这个问题,我似乎无法找到一个解决方案让我的工作.任何建议或帮助表示赞赏.

码:

   package com.example.webview;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.speech.tts.TextToSpeech;
import android.text.method.ScrollingMovementMethod;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ReadOut extends Activity implements TextToSpeech.OnInitListener, OnClickListener {


    boolean paused = false;
    String leftToRead = null;
    String res = null;

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.read_out);
        Intent intent = getIntent();
        res = intent.getExtras().getString("response"); …
Run Code Online (Sandbox Code Playgroud)

java android

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

fgets()包括最后的换行符

fgets(input,sizeof(input),stdin);
if (strcmp(input, "quit") == 0){
  exit(-1);
}
Run Code Online (Sandbox Code Playgroud)

如果我输入quit,它不会退出程序; 我想知道为什么会这样.

顺便input声明为char *input;.

c string fgets

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

C将char附加到char*

所以我试图追加char一个char*.

例如,char *word = " "; 我也有char ch = 'x';

append(word, ch);用这个方法..

void append(char* s, char c)
{

    int len = strlen(s);
    s[len] = c;
    s[len+1] = '\0';
}
Run Code Online (Sandbox Code Playgroud)

它给了我一个分段错误,我理解为什么我想.因为s[len]是出界的.我该如何制作呢?char*如果我要使用像char word [500]这样的东西,我还需要清除很多东西; 一旦附加了一些字符,我该如何清除?请问strlen它永远是500?提前致谢.

c string append char segmentation-fault

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

C基本头部命令

我正在尝试从linux中为我的编程类重新创建head和tail命令.我们刚开始使用C,所以我对分配内存和指针的想法不熟悉.我想知道为什么这不起作用.

#include <stdio.h>
#include <stdlib.h>

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

    /* Checks if correct amount of arguements */

    if(argc != 2 || argc != 4){
        printf("Usage: %s head <file> \n Or: head <file> -n <number of characters>", argv[0]);
        exit(-1);
    }

    if(strcmp(argv[1], "-n" != 0)){
        char fileName[strlen(argv[1])] = argv[1];
    }
}

//Compile error on char fileName[strlen(argv[1])] = argv[1];
Run Code Online (Sandbox Code Playgroud)

任何其他见解也会有所帮助.

c linux tail head

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

C功能指针不幸事故

好的,所以我正在尝试学习函数指针.我有一个像这样的基本函数指针设置.

打印链表的功能:

void seq_print(Seq seq, void (* print_func)(void *)){
Node * p = seq->top;
    if(p == NULL){
        printf("%s %c", "There is no data to print.", '\n');
        return;
    }
    while(p != NULL){
        print_func(p->data);
        p = p->next;
    }
}
Run Code Online (Sandbox Code Playgroud)

测试功能:

seq_print(s, printFunc(1));
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

seq.h:113:32: error: expected declaration specifiers or ‘...’ before ‘(’ token
 extern void seq_print(Seq seq, (void *) print_func(void *));
Run Code Online (Sandbox Code Playgroud)

我真的不确定该怎么做,任何见解都会有所帮助.

c pointers function

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

C基本字符串返回函数

我仍然是C的新手.我仍然无法理解所有指针.我正在尝试创建一个返回String的方法.这是功能,它仍然不完整.

char getS(char *fileName){
    FILE *src;
    if((src = fopen(fileName, "r")) == NULL){
        printf("%s %s %s", "Cannot open file ", fileName, ". The program is now ending.");
        exit(-1);
    }
    char *get = " ";        
    //insert getting a random word here
    return(*get);
}
Run Code Online (Sandbox Code Playgroud)

而我正试图像这样调用这个方法

char *article = getS("articles.txt");
char *noun = getS("nouns.txt");
char *verb = getS("verbs.txt");
Run Code Online (Sandbox Code Playgroud)

编译器给我这个:

error: invalid type argument of unary ‘*’ (have ‘int’)
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

c string methods pointers function

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

递归二叉树插入

所以我试图使用这个递归函数将值插入二叉树:

void add(node* *hd, int v){
node* curr = *hd;
if(curr == NULL){
    curr = (node*)malloc(sizeof(node));
    curr->value = v;
}else{
    if(v < curr->value){
        add(&curr->left, v);
    }else{
        add(&curr->right, v);
    }
}
}
Run Code Online (Sandbox Code Playgroud)

它似乎没有用,我只是不明白为什么我不能做这样的事情.我该怎么办呢?

c tree recursion binary-tree insertion

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

二叉树的后序/预订遍历

我有一个预订遍历函数,如下所示:

void listInPreOrder(node* hd){
if(hd != NULL) {
        printf("%d, ", hd->value);
        listInPreOrder(hd->left);
        listInPreOrder(hd->right);
    }
}
Run Code Online (Sandbox Code Playgroud)

这实际上是有效的,但我认为将它发布到订单就像这样简单

void listInPostOrder(node* hd){
if(hd != NULL) {
        listInPreOrder(hd->left);
        listInPreOrder(hd->right);
        printf("%d, ", hd->value);
    }
}
Run Code Online (Sandbox Code Playgroud)

但遗憾的是,它并没有那么好用.我想知道如何解决这个问题,也许我正在做一些简单的错误.或许这是完全错误的.

c tree recursion binary-tree postorder

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

C分段故障

您好抱歉所有问题,但是当我运行此代码时,我的终端窗口上出现"分段错误(核心转储)".

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static int usage (void) {
    printf("Usage: head <file>\n");
    printf("   Or: head <file> -n <number of characters>\n");
    printf("   Or: head -n <number of characters> <file>\n"); 
    return -1;
}

int main (int argc,char **argv) {
    if ((argc != 2) && (argc != 4)) return usage();

    char *fileName = argv[1];
    int lineCount = 10;
    FILE *src;

    if ((argc == 4) && (strcmp(argv[1], "-n" != 0))){
        fileName = argv[1];
        lineCount = argv[3]; 
        puts("-n in last position");
    }else{ …
Run Code Online (Sandbox Code Playgroud)

c linux fopen file head

0
推荐指数
2
解决办法
1406
查看次数

C指针和数组不兼容的类型

所以我想知道为什么我不能这样做.

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

    FILE *src;
    char filePath[261];
    filePath = argv[1];
Run Code Online (Sandbox Code Playgroud)

最后一行是存在编译器错误的地方.char []和char*之间有什么区别?我如何修复此代码,以便将filePath设置为等于argv [1].提前致谢.

c arrays types pointers

0
推荐指数
1
解决办法
500
查看次数