我正在创建一个链接列表,就像我上一个问题一样.我发现开发链表的最好方法是将头部和尾部放在另一个结构中.我的产品结构将嵌套在这个结构中.我应该将列表传递给添加和删除功能.我发现这个概念令人困惑.
我已经实现了initialize,add和clean_up.但是,我不确定我是否正确地做到了这一点.
当我将产品添加到列表中时,我使用calloc声明了一些内存.但我想我不应该为产品声明内存.我对此添加感到困惑.
非常感谢任何建议,
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PRODUCT_NAME_LEN 128
typedef struct product_data
{
int product_code;
char product_name[PRODUCT_NAME_LEN];
int product_cost;
struct product_data_t *next;
}product_data_t;
typedef struct list
{
product_data_t *head;
product_data_t *tail;
}list_t;
void add(list_t *list, int code, char name[], int cost);
void initialize(list_t *list);
void clean_up(list_t *list);
int main(void)
{
list_t *list = NULL;
initialize(list);
add(list, 10, "Dell Inspiron", 1500);
clean_up(list);
getchar();
return 0;
}
void add(list_t *list, int code, char name[], int cost) …Run Code Online (Sandbox Code Playgroud) VS 2005 SP3
我曾多次与进度条合作过.
但是,我需要一个垂直的.但是,我找不到任何会旋转它的属性.
进度条是否始终处于水平位置且无法更改.
非常感谢,
gcc 4.4.1 c89
我有以下代码片段:
#include <stdlib.h>
#include <stdio.h>
char *buffer = malloc(10240);
/* Check for memory error */
if(!buffer)
{
fprintf(stderr, "Memory error\n");
return 1;
}
printf("sizeof(buffer) [ %d ]\n", sizeof(buffer));
Run Code Online (Sandbox Code Playgroud)
但是,sizeof(缓冲区)总是打印4.我知道char*只有4个字节.但是,我已经分配了10kb的内存.那么尺寸不应该是10240吗?我想知道我在想什么?
非常感谢任何建议,
gcc 4.4.4 c89
我正在使用下面的代码.但是,我一直得到相同的数字:
size_t i = 0;
for(i = 0; i < 3; i++) {
/* Initialize random number */
srand((unsigned int)time(NULL));
/* Added random number (simulate seconds) */
add((rand() % 30) + 1);
}
Run Code Online (Sandbox Code Playgroud)
我想回到0到30.但是,我最后一次跑这个三次得了17次.
非常感谢,
git version 1.7.1
svn, version 1.6.12
Ubuntu 10.10
Run Code Online (Sandbox Code Playgroud)
我只是git而且我使用过svn.但我没有一起使用过.我有一个git存储库,我不得不将我的存储库更多地转换为subversion版本.所以我一直在使用git-svn.大部分时间都可以.但是,我发现围成一圈.
我是唯一一个从事这个项目的人.
我对我的分支进行了一些更改.我然后上演他们:
git stage gateway.c
Run Code Online (Sandbox Code Playgroud)
然后在本地将它们提交给git:
git commit m"Made some changes"
Run Code Online (Sandbox Code Playgroud)
然后我想将它们提交给颠覆.获取最新更新:
git svn rebase
Run Code Online (Sandbox Code Playgroud)
然后我收到以下消息:
It seems that I cannot create a rebase-apply directory, and
I wonder if you are in the middle of patch application or another
rebase. If that is not the case, please
rm -fr /home/joe/projects/gateway/.git/rebase-apply
and run me again. I am stopping in case you still have something
valuable there.
rebase refs/remotes/trunk: command returned error: 1 …Run Code Online (Sandbox Code Playgroud) 我正在使用不同版本的gcc的2台不同机器上编译我的源代码.
cflags c89
-Wall -Wextra -Wunreachable-code -g -m32 -D_DEBUG -O0 -D_LARGEFILE64_SOURCE -D_REETRANT -D_THREAD_SAFE
Run Code Online (Sandbox Code Playgroud)
一个是redhat-4
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46)
Linux 203_test_server 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
一个是Fedora 18
gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)
Linux localhost.localdomain 3.8.1-201.fc18.x86_64 #1 SMP Thu Feb 28 19:23:08 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
我的fedora 18编译没有错误.但是,在redhat 4机器上我遇到了一些错误.
channel.h:35: error: redefinition of typedef ‘channel_t’
internal.h:19: error: previous declaration of ‘channel_t’ was here
Run Code Online (Sandbox Code Playgroud)
我认为错误只是一个循环问题.但是,使用相同的代码库,在2台不同的机器上进行编译真的可以使用2个不同版本的gcc来改变它们吗?
我在考虑使用较新版本的编译器会产生更多错误,因为较新的编译器可能会更严格.
这不是解决错误的问题,而是编译器的一般问题. …
Android Studio 1.5
Run Code Online (Sandbox Code Playgroud)
我调用chat_profile_header了这个布局,将在许多布局中使用.我已经设定background为靛蓝色.问题是当我在其他布局中包含此标题时,我希望能够根据该布局的主题更改背景颜色.标题中的所有内容都将保持不变.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/profile_header_indigo_500">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/photorace"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/tvProfileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/profile_image"
android:layout_toEndOf="@id/profile_image"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:fontFamily="sans-serif"
android:textColor="@android:color/white"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这里我使用的是此布局中包含的上述标题.但是,基于这个主题,我想将标题更改为另一种background颜色灰色.但是,我认为我不能覆盖背景颜色属性.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<include
layout="@layout/chat_profile_header"
android:background="@color/child_header_lighter_grey"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvParentList"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点,而无需根据背景创建不同的页眉布局.似乎有很多重复.
Android Studio 2.1.2
Run Code Online (Sandbox Code Playgroud)
我有这个警告,我似乎无法找到原因.我没有使用任何原始类型.
Unchecked call to attachView(DownloadViewContract) as a member of raw type
Run Code Online (Sandbox Code Playgroud)
我有以下界面
public interface DownloadPresenterContract {
interface Operations<DownloadViewContract> {
void attachView(DownloadViewContract view);
void detachView();
void getData();
}
}
Run Code Online (Sandbox Code Playgroud)
以及以下实施
public class DownloadPresenterImp implements
DownloadPresenterContract.Operations<DownloadViewContract> {
private DownloadViewContract mView;
private DownloadPresenterImp() {
}
public static DownloadPresenterImp getNewInstance() {
return new DownloadPresenterImp();
}
/* Operations */
@Override
public void attachView(DownloadViewContract view) {
mView = view;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的视图界面
public interface DownloadViewContract {
void onSuccessDownload();
void onFailureDownload(String errMsg);
}
Run Code Online (Sandbox Code Playgroud)
在我的片段中,这是我的观点 …
Android Studio 2.3 RC 1
Run Code Online (Sandbox Code Playgroud)
我正在使用MVP架构并希望运行JVM单元测试.
在我的模型中,我使用Retrofit2和RxJava从API获取电影.我想测试函数getPopularMovies(...)但是,这个函数会调用webserver.但是,在测试中我想以某种方式模拟这个并且只是测试onSuccess()和onFailure()调用方法.
我的模型类看起来像这个片段只是为了保持简短:
public class MovieListModelImp implements MovieListModelContract {
@Override
public void getPopularMovies(PopularMovieResultsListener popularMovieResultsListener) {
mSubscription = mMovieAPIService.getPopular(Constants.MOVIES_API_KEY)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Results>() {
@Override
public void onCompleted() {
Timber.d("onCompleted");
}
@Override
public void onError(Throwable e) {
Timber.e(e, "onError");
popularMovieResultsListener.onFailure(e.getMessage());
}
@Override
public void onNext(Results results) {
Timber.d("onNext %d", results.getResults().size());
popularMovieResultsListener.onSuccess(results);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
和界面:
public interface MovieListModelContract {
interface PopularMovieResultsListener {
void onFailure(String errorMessage);
void onSuccess(Results popularMovies);
} …Run Code Online (Sandbox Code Playgroud) Android Studio 3.1 RC 2
kotlin 1.2.30
Run Code Online (Sandbox Code Playgroud)
Java中fetchMessage的签名
Single<Response> fetchMessage(final String Id);
Run Code Online (Sandbox Code Playgroud)
kotlin代码
fun translate(Id: String): Completable {
return repository.fetchMessage(Id)
.flatMap {
Single.fromCallable<State>({
update(messageId, it, State.COMPLETED)
State.COMPLETED
})
}
.onErrorReturn({
update(Id, null, State.ERROR)
State.ERROR
})
.toCompletable()
}
Run Code Online (Sandbox Code Playgroud)
我想在fetchMessage之前运行的方法
fun insertMessage(Id: String): Completable {
return Completable.fromCallable {
insert(Id, State.IDLE)
}
}
Run Code Online (Sandbox Code Playgroud)
我希望insertMessage e以某种方式在fetchMessage之前运行.我在考虑使用concatMap但不确定如何组合translate和insertMessage.这样insertMessage将首先运行,然后一旦完成,将运行translate.
非常感谢任何建议,
Update solution 1 using startWith(..):
Run Code Online (Sandbox Code Playgroud)
通过将translate的返回值更改为Single.我这样做了:
fun translate(Id: String): Single<State> {
return repository.fetchMessage(Id)
.flatMap {
Single.fromCallable<State>({
update(messageId, it, State.COMPLETED)
State.COMPLETED
})
}
.onErrorReturn({
update(Id, null, State.ERROR)
State.ERROR …Run Code Online (Sandbox Code Playgroud)