此处的代码:http://ideone.com/AZnXFm
@Bean
public Server rsServer() {
JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
endpoint.setBus(bus);
endpoint.setProvider(new JacksonJsonProvider());
endpoint.setServiceBeans(asList(new CustomerServiceDefault()));
endpoint.setAddress("/");
endpoint.setFeatures(asList(new Swagger2Feature()));
return endpoint.create();
}
输出
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
char *buffer;
size_t bufsize = 32;
size_t characters;
buffer = (char *)malloc(bufsize * sizeof(char));
if( buffer == NULL)
{
perror("Unable to allocate buffer");
exit(1);
}
printf("Type something: ");
characters = getline(&buffer,&bufsize,stdin);
printf("%zu characters were read.\n",characters);
printf("You typed: %s",buffer);
char *end_str,*token2;
char *token = strtok_r(buffer,";",&end_str);
printf("token : %s \n", token);
int count =0,wordcnt=0;
while(token !=NULL)
{
char *end_token;
count++;
printf("outside count ------------------------%d\n", count);
strtok_r(token," ",&end_token);
while(token2!=NULL)
{
wordcnt++;
printf("insdie count %d\n",wordcnt);
printf("%s------------------- \n", token2);
token2 = strtok_r(NULL," ",&end_token);
}
token = strtok_r(NULL, ";",&end_str);
}
return(0);
}
答案 0 :(得分:1)
以下代码中需要或已应用了许多基本修复:
getline()
进行内存分配。getline()
是否读了一行。token2
电话设置strtok_r()
。characters
设为ssize_t
以匹配getline()
的回复。characters
打印%zd
。这有点争议;它使用size_t
- 限定的带符号十进制格式字符串打印带有z
的带符号变体。它是有道理的(至少对我来说和我的编译器 - macOS Sierra上的GCC 6.2.0),但我不确定在哪里可以找到它被(POSIX)标准正式批准的确认。导致:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char *buffer = 0;
size_t bufsize = 0;
ssize_t characters;
printf("Type something: ");
characters = getline(&buffer, &bufsize, stdin);
printf("%zd characters were read.\n", characters);
if (characters > 0)
{
printf("You typed: %s", buffer);
char *end_str1;
char *token1 = strtok_r(buffer, ";", &end_str1);
printf("token: %s \n", token1);
int count = 0, wordcnt = 0;
while (token1 != NULL)
{
char *end_str2;
count++;
printf("outside count ------------------------%d\n", count);
char *token2 = strtok_r(token1, " ", &end_str2);
while (token2 != NULL)
{
wordcnt++;
printf("inside count %d\n", wordcnt);
printf("%s------------------- \n", token2);
token2 = strtok_r(NULL, " ", &end_str2);
}
token1 = strtok_r(NULL, ";", &end_str1);
}
}
free(buffer);
return(0);
}
示例运行:
Type something: rosie is; really good
22 characters were read.
You typed: rosie is; really good
token: rosie is
outside count ------------------------1
inside count 1
rosie-------------------
inside count 2
is-------------------
outside count ------------------------2
inside count 3
really-------------------
inside count 4
good
-------------------