/****************************************************************************/
/* プログラム名 : 基本課題1-8 */
/* プログラムID : kadai1-8 */
/*--------------------------------------------------------------------------*/
/* 変更日 : 2012年09月13日 */
/* 変更内容 : コメント・ヘッダ入れる & 入力処理 */
/****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
void nhap(char s[128], int dodai);
void kiemtra(char s[128]);
int ilengis2(char s[128]);
void main()
{
float hienthi;
/****************************************************/
/* dem : 最初の値と入力した値をカウントするの値。 */
/****************************************************/
char s[129];
printf("Input value from -9999 to 9999\n\n"); nhap(s, 128);
if((hienthi > 9999) || (hienthi < -9999))
{
printf("--- not in -9999 ---> 9999. But that is number\n ---\n"); }
else
{
printf("Your input is NUMBER in -9999 to 9999\n"); printf("hienthi = %f\n", hienthi
); }
printf("--- Press enter key to exit ---\n"); }
/****** INPUT PROCESS ********/
void nhap(char s[128], int dodai)
{
/*****************************************************/
/* Win 64bitにCMDで127以上の文字入力可能ので、 */
/* このFUNCTIONを呼び出すとき、必ず127以下を使用する*/
/*****************************************************/
int cnt=0,i;
{
if(cnt < dodai)
{
s[cnt]=i;
cnt++;
}
}
s[cnt++]='\0';
kiemtra(s);
}
void kiemtra(char s[128])
{
int i_error=0; /* 0 is ok, 1 is re-input */
int ileng;
int dotto=0, mainasu=0, moji=0, cnt=0;
if(ileng == 0)
{
i_error=1;
}
else if(ileng > 127)
{
i_error=1;
}
else if(ileng == 1)
{
{
i_error=1;
}
}
else if(ileng == 2)
{
i_error=ilengis2(s);
}
else /* total char from 3 -> 127 */
{
i_error=ilengis2(s);
if(i_error != 1)
{
for(cnt=0; cnt<ileng; cnt++)
{
if((s
[cnt
] != '.') && (s
[cnt
] != '-') && (!isdigit(s
[cnt
]))) {
i_error=1;
break;
}
/* dotto count */
if(s[cnt] == '.')
{
dotto++;
}
if(dotto > 1)
{
printf("「.」は2つ以上の場合、不明の数字です。\n"); i_error=1;
break;
}
/* 「-」place check */
if((s[cnt] == '-') && (cnt != 0))
{
i_error=1;
break;
}
}
}
}
if(i_error == 1)
{
nhap(s, 128);
}
}
int ilengis2(char s[128])
{
int i_error; /* return value. 0 is ok, 1 is re-input*/
int dotto=0, mainasu=0;
if(s[0] == '.')
{
dotto=1;
}
else if(s[0] == '-')
{
mainasu=1;
}
{
i_error=1;
}
if((dotto > 0) || (mainasu > 0))
{
/* the second character is not number */
{
i_error=1;
}
}
{
if((mainasu > 0) || (dotto > 0))
{
i_error=1;
}
else if(i_error != 1)
{
if((dotto == 0) && (s[1] != '.' ))
{
i_error=1;
}
}
}
return i_error;
}