我在我的项目中得到“java:package org.junit 不存在”,这让我发疯。我有 JUnit 作为外部库,但它仍然无法识别。我正在尝试在 IntelliJ Idea 中设置一个简单的“Hello World”应用程序。
这是我的pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.springapp</groupId>
<artifactId>untitled</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>untitled</name>
<properties>
<spring.version>4.1.1.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>untitled</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes> …Run Code Online (Sandbox Code Playgroud) 所以我想一次从stdin读一个字节。while循环的每次迭代都试图重新分配缓冲区,但是我不想使用realloc。这是我尝试过的:
char tempChar = '\0';
char *buffer;
int bufferSize = 0;
buffer = (char*) malloc(sizeof(char));
while((tempChar = getc(stdin)) != EOF)
{
buffer[bufferSize] = tempChar;
bufferSize++;
char *temp = buffer;
buffer = (char*)malloc(sizeof(char)*bufferSize);
memcpy(buffer, temp, sizeof(temp));
free(temp);
}
buffer[bufferSize] = '\0';
Run Code Online (Sandbox Code Playgroud)
我遇到了细分错误。知道为什么会这样吗?
编辑:好的,就像其他人所说的,我修复了两个错误。这是固定版本:
char tempChar = '\0';
char *buffer;
int bufferSize = 1;
int count = 0;
buffer = malloc(sizeof(char));
while((tempChar = getc(stdin)) != EOF){
buffer[count] = tempChar;
count++;
if(count >= bufferSize){
bufferSize *= 2;
char *temp = buffer;
buffer = …Run Code Online (Sandbox Code Playgroud)