小编nai*_*n33的帖子

换行符字符缩进?(JAVA)

我试图使用\n创建一个字符串列表,但每当我添加多个字符串时,字符串缩进到前一个字符串的点,所以示例输出将是:

0 hello nain
            1 test nain
                       2 huh nain
Run Code Online (Sandbox Code Playgroud)

我不知道为什么这样做.这是我创建字符串的代码:

            String[] posts = currentTopic.getMessages("main");
            //String[] postsOutput = new String[posts.length];
            String postsOutput = "0 " + posts[0];

            for(int i = 1; i < posts.length; i++){
                postsOutput += "\n" + i + " " + posts[i];
                //postsOutput[i] = i + posts[i];
            }

            sc.close();
            return postsOutput;
Run Code Online (Sandbox Code Playgroud)

我也尝试将\n移动到附加的末尾,但结果仍然相同.任何帮助,将不胜感激.

谢谢

java string newline indentation

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

将结构指针传递给C中的函数

我无法将结构传递给一个以结构指针作为参数的函数,并且不断收到错误"错误:一元的无效类型参数'*'(有'StackNode')"

这是我的代码的必要部分(不是全部):

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

struct stackNode{
    char data;
    struct stackNode *nextPtr;
};
typedef struct stackNode StackNode;
typedef StackNode *StackNodePtr;

void convertToPostfix(char infix[], char postfix[]);
int isOperator(char c);
int precedence(char operator1, char operator2);
void push(StackNodePtr *topPtr, char value);
char pop(StackNodePtr *topPtr);
char stackTop(StackNodePtr topPtr);
int isEmpty(StackNodePtr topPtr);
void printStack(StackNodePtr topPtr);

int main(){
    convertToPostfix(NULL, NULL);
    return 0;
}

void convertToPostfix(char infix[], char postfix[]){
    StackNode stack = {'(', NULL};
    push(*stack, 'a');
    printStack(&stack);
}

void push(StackNodePtr* topPtr, char value){
    topPtr->nextPtr = NULL; …
Run Code Online (Sandbox Code Playgroud)

c structure function

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

标签 统计

c ×1

function ×1

indentation ×1

java ×1

newline ×1

string ×1

structure ×1