ページ 1 / 1
execlpの使い方
Posted: 2012年10月26日(金) 17:10
by ピエトロ
キーボードから年と月を入力し、execlpとプログラム「cal」を使ってカレンダーを表示するプログラムを作りたいのですが、コンパイルしたら年と月を入力するところまでしか動きません。
どなたかよろしくお願いします。
コード:
#include <stdio.h>
#include <unistd.h>
int main(void)
{
int month = 1;
int year = 2012;
printf("年を入力してください\n");
scanf("%d",&year);
printf("月を入力してください\n");
scanf("%d",&month);
execlp("cal","cal",month,year,NULL);
return 0;
}
Re: execlpの使い方
Posted: 2012年10月26日(金) 17:27
by ホヅミ
入力パラメータは整数型ではなく文字列型だと思います。
コード:
#include <stdio.h>
#include <unistd.h>
int main(void)
{
char month[3];
char year[5];
printf("年を入力してください\n");
scanf("%s",year);
printf("月を入力してください\n");
scanf("%s",month);
execlp("cal","cal",month,year,NULL);
return 0;
}
Re: execlpの使い方
Posted: 2012年10月26日(金) 18:00
by ピエトロ
無事に完成しました。
回答ありがとうございます。